个推-Android集成
16lz
2021-01-24
最近在集成个推,做个笔记。
在个推平台上Android有两种推送方式:推送和透传。
一开始进行基本的信息配置,贴上官方文档配置步骤
一、首先来说一下推送,我所做的推送比较简单,没有自定义通知栏,也没有复写继承Service,个推本身带的通知栏已经够用了,还有PushService也够用。
接受推送有两种方式:receiver或者service。我采用的是servicer继承GTIntentService
,在初始化之后必须调用方法:registerPushIntentService,否则接收不到消息。
二、其次便是透传,onReceiveMessageData方法回调传回数据,需要自定义通知栏,ps:还是自定义的通知栏好用
注意:不可多次调用registerPushIntentService,否则发生crash,service会不起作用。建议在调用此方法之前调用stopService方法,采取如下调用顺序。
PushManager.getInstance().stopService(this.getApplicationContext());PushManager.getInstance().initialize(this.getApplicationContext(), PushService.class);PushManager.getInstance().registerPushIntentService(this.getApplicationContext(), DemoIntentService.class);
在notification的设置中需要注意的是,避免当前activity被再次new导致栈内有两个相同的activity,需要做如下设置:
intent.addCategory(Intent.CATEGORY_LAUNCHER);//此处必须有,否则会有两个mainactivityintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);//此处必须有,否则会有两个mainactivity
更多相关文章
- android 预装第三方apk的方法(非system priv-app)
- android 自学日记(五) ——ListView
- Android(安卓)Uri、UriMatcher、ContentUris详解
- 【Android】主线程调用Http请求无效
- 利用Android两行代码真正杀死你的App
- 变更到Android4.4的问题
- android startActivityForResult的用法
- Android中隐式Intent的匹配规则
- Android(安卓)Studio 中 gradle 的两个版本号对应关系