mysql数据库白羽_Android应用开发Android 友盟推送原理解析

本文将带你了解Android应用开发Android 友盟推送原理解析,希望本文对大家学Android有所帮助。

72ee2fc20cbef67d02cec7f95f9a72c1.png

Android   友盟推送原理解析,最近项目使用推送是友盟推送,实际上推送原理相同,但是友盟推送和极光推送在Android端的代码编写还是有很大差别的。极光推送我记得是定义广播,然后在广播中发送通知,在设置跳转以一类的,但是在友盟推送中,友盟封装好了,有响应的回调接口。

友盟推送自定义通知:

final UmengMessageHandler messageHandler = new UmengMessageHandler()   {

//自定义通知

@Override

public Notification   getNotification(Context context, UMessage msg) {

switch   (msg.builder_id) {

case   BUILD_ID:

return   super.getNotification(context, msg);

default:

//默认为0,若填写的builder_id并不存在,也使用默认。

Notification.Builder builder = new   Notification.Builder(context);

RemoteViews   myNotificationView = new RemoteViews(context.getPackageName(),

R.layout.notification_view);

myNotificationView.setTextViewText(R.id.notification_title,   msg.title);

myNotificationView.setTextViewText(R.id.notification_text,   msg.text);

myNotificationView.setImageViewBitmap(R.id.notification_large_icon,   getLargeIcon(context, msg));

myNotificationView

.setImageViewResource(R.id.notification_small_icon,   getSmallIconId(context, msg));

builder.setContent(myNotificationView)

.setSmallIcon(getSmallIconId(context, msg))

.setTicker(msg.ticker)

.setAutoCancel(true);

return   builder.build();

}

}

//自定义消息

@Override

public void   dealWithCustomMessage(final Context context, final UMessage msg) {

new   Handler(context.getMainLooper()).post(new Runnable() {

@Override

public void run()   {

//   对于自定义消息,PushSDK默认只统计送达。若开发者需要统计点击和忽略,则需手动调用统计方法。

boolean   isClickOrDismissed = true;

if   (isClickOrDismissed) {

//自定义消息的点击统计

UTrack.getInstance(context).trackMsgClick(msg);

} else   {

//自定义消息的忽略统计

UTrack.getInstance(context).trackMsgDismissed(msg);

}

Toast.makeText(context, msg.custom, Toast.LENGTH_LONG).show();

}

});

}

};

PushAgent.getInstance(context).setMessageHandler(messageHandler);

点击通知跳转的回调,友盟已经帮我们写好了:

UmengNotificationClickHandler notificationClickHandler = new   UmengNotificationClickHandler() {

@Override

public void launchApp(Context   context, UMessage msg) {

super.launchApp(context,   msg);

/**

* TODO 点击跳转,后续处理

*/

}

};

PushAgent.getInstance(context).setNotificationClickHandler(notificationClickHandler);

如果需要跳转到相应的activity,就需要和服务器约定了 ,并且在友盟开发者平台配置。

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值