参考文章
https://github.com/YoloHuang/PushLibrary
需求描述
最近要做推送相关的东西,主要是看了友盟的,它虽然可以集成厂商的通道,但是有推送的限制,在看完文档后,还有一个给我的感觉就是,当我把手机里面所有的APP都干死后,就不可能收到推送了。公司的业务需求就是干死APP也要收到推送,所以就只能自己集成厂商通道来操作,就发现上面黏贴的一个gitHub地址,他写的还是很好的但是作者久久没更新,我就自己又模仿着他鲁了一份gitHub
业务代码大概介绍图
使用方法
//这里初始化各种平台的对象
PushTargetManager.getInstance().init(this.getApplication());
//拿到对应的对象
BasePushTargetInit basePushTargetInit = PushTargetManager.getInstance().getmPushTarget();
String aligis="abcd";
if (basePushTargetInit!=null && !TextUtils.isEmpty(aligis)){
if (basePushTargetInit instanceof JPushInit){
JPushInit jPushInit = (JPushInit) basePushTargetInit;
jPushInit.deleteAlias(0);
}else if (basePushTargetInit instanceof HuaWeiInit){
HuaWeiInit huaWeiInit = (HuaWeiInit) basePushTargetInit;
huaWeiInit.deleteToken();
}else if (basePushTargetInit instanceof XiaomiInit){
XiaomiInit xiaomiInit = (XiaomiInit) basePushTargetInit;
xiaomiInit.deleteAlias(aligis);
}else if (basePushTargetInit instanceof MeiZuInit){
MeiZuInit meiZuInit = (MeiZuInit) basePushTargetInit;
meiZuInit.deleteAlias(aligis);
}
}
//注册广播监听
if (pushBroadcastReceiver==null){
pushBroadcastReceiver = new PushBroadcastReceiver();
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(PUSH_RECEIVE_INIT_RESULT);//初始化成功回调
intentFilter.addAction(PUSH_RECEIVE_MESSAGE);//得到透传消息
intentFilter.addAction(PUSH_RECEIVE_NOTIFICATION);//收到后台推送
intentFilter.addAction(PUSH_RECEIVE_NOTIFICATION_CLICK);//用户点击推送
intentFilter.addAction(PUSH_RECEIVE_OTHER_OPTIONS);//其它事情操作
intentFilter.addAction(PUSH_RECEIVE_ALIAS);//其它事情操作
LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver,intentFilter);
其它想说的
1、透传跟通知是2回事,透传不会给你类似通知的那样显示出来
2、做华为推送的时候 agconnect-services.json 这个文件,每个包名不同,需要自行到华为上下载