推送其实挺中意小米推送的,并经用户群占比还是比较大的,奈何拗不过php后端哥们的选型,就只好用信鸽推送了,期间接入过程中也是遇到不少问题,所以记录下来,以后如果还是用信鸽推送的话,估计看看以前的博客,也能少踩点坑。

因为最新版本是2.43,所以按照2.43的引入为准

1,导入jar包和so文件:

文件夹为信鸽推送必须的so文件:

2,针对so文件,gradle文件进行配置,生成第一张图里面的native_libs2的jar文件:

3,AndroidManifest.xml文件的配置,这个基本按照官网demo文件里面写的就行:

<!--(信鸽推送相关)--><!-- 【必须】 (2.30及以上版新增)展示通知的activity --><activityandroid:name="com.tencent.android.tpush.XGPushActivity"android:theme="@android:style/Theme.Translucent"android:exported="false"><intent-filter><!-- 若使用AndroidStudio,请设置android:name="android.intent.action"--><action android:name="android.intent.action"/></intent-filter></activity><!-- 【必须】 信鸽receiver广播接收 --><receiverandroid:name="com.tencent.android.tpush.XGPushReceiver"android:process=":xg_service_v2"><intent-filter android:priority="0x7fffffff"><!-- 【必须】 信鸽SDK的内部广播 --><action android:name="com.tencent.android.tpush.action.SDK"/><action android:name="com.tencent.android.tpush.action.INTERNAL_PUSH_MESSAGE"/><!-- 【必须】 系统广播:网络切换 --><action android:name="android.net.conn.CONNECTIVITY_CHANGE"/><!-- 【可选】 系统广播:开屏 --><action android:name="android.intent.action.USER_PRESENT"/><!-- 【可选】 一些常用的系统广播,增强信鸽service的复活机会,请根据需要选择。当然,你也可以添加APP自定义的一些广播让启动service --><action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/><action android:name="android.intent.action.ACTION_POWER_CONNECTED"/><action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/></intent-filter><!-- 【可选】 usb相关的系统广播,增强信鸽service的复活机会,请根据需要添加 --><intent-filter android:priority="0x7fffffff"><action android:name="android.intent.action.MEDIA_UNMOUNTED"/><action android:name="android.intent.action.MEDIA_REMOVED"/><action android:name="android.intent.action.MEDIA_CHECKING"/><action android:name="android.intent.action.MEDIA_EJECT"/><data android:scheme="file"/></intent-filter></receiver><!-- 【必须】 信鸽service --><serviceandroid:name="com.tencent.android.tpush.service.XGPushService"android:exported="true"android:persistent="true"android:process=":xg_service_v2"/><!-- 【必须】 通知service,其中android:name部分要改为当前包名 --><serviceandroid:name="com.tencent.android.tpush.rpc.XGRemoteService"android:exported="true"><intent-filter><!-- 【必须】 请修改为当前APP名包.PUSH_ACTION,如demo的包名为:com.qq.xgdemo --><action android:name="你的包名.PUSH_ACTION"/></intent-filter></service><!-- 【可选】APP实现的Receiver,用于接收消息透传和操作结果的回调,请根据需要添加 --><!-- YOUR_PACKAGE_PATH.CustomPushReceiver需要改为自己的Receiver: --><receiverandroid:name=".push.MessageReceiver"android:exported="false"><intent-filter><!-- 接收消息透传 --><action android:name="com.tencent.android.tpush.action.PUSH_MESSAGE"/><!-- 监听注册、反注册、设置/删除标签、通知被点击等处理结果 --><action android:name="com.tencent.android.tpush.action.FEEDBACK"/></intent-filter></receiver> <!-- 【必须】 请修改为APP的AccessId,“21”开头的10位数字,中间没空格 --><meta-dataandroid:name="XG_V2_ACCESS_ID"android:value="你的AccessId"/><!-- 【必须】 请修改为APP的AccessKey,“A”开头的12位字符串,中间没空格 --><meta-dataandroid:name="XG_V2_ACCESS_KEY"android:value="你的AccessKey"/>

还有就是相关权限:

<!-- 【必须】 信鸽SDK所需权限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- 【可选】 信鸽SDK所需权限 -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BATTERY_STATS" />

虽然很多,但是没办法,毕竟是中国特色,推送只能这样,才能勉强能够保证推送到达率。

4,相关代码的集成:

如上其实都是可以从demo文件里面拷贝出来的,其中messageReceiver是最重要的类,因为主要的推送信息是从这个类里面获取的。

public class MessageReceiver extends XGPushBaseReceiver {private             Intent intent = new Intent("com.qq.xgdemo.activity.UPDATE_LISTVIEW");public static final String LogTag = "TPushReceiver";//private void show(Context context, String text) {//    Toast.makeText(context, text, Toast.LENGTH_SHORT).show();//}// 通知展示,主要控制推送来的信息在状态栏的展示,当然如果想自定义可以修改这个方法
    @Overridepublic void onNotifactionShowedResult(Context context, XGPushShowedResult notifiShowedRlt) {if (context == null || notifiShowedRlt == null) {return;}XGNotification notific = new XGNotification();notific.setMsg_id(notifiShowedRlt.getMsgId());notific.setTitle(notifiShowedRlt.getTitle());notific.setContent(notifiShowedRlt.getContent());// notificationActionType==1为Activity,2为url,3为intent
        notific.setNotificationActionType(notifiShowedRlt.getNotificationActionType());// Activity,url,intent都可以通过getActivity()获得
        notific.setActivity(notifiShowedRlt.getActivity());notific.setUpdate_time(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));NotificationService.getInstance(context).save(notific);context.sendBroadcast(intent);String customContent = notifiShowedRlt.getCustomContent();KLog.json(customContent);}//反注册,注意在你用的activity里面的ondestory里面反注册@Override public void onUnregisterResult(Context context, int errorCode) {KLog.i("onUnregisterResult");if (context == null) {return;}String text = "";if (errorCode == XGPushBaseReceiver.SUCCESS) {text = "反注册成功";}else {text = "反注册失败" + errorCode;}KLog.i(LogTag, text);//show(context, text);
    }@Overridepublic void onSetTagResult(Context context, int errorCode, String tagName) {KLog.i("onSetTagResult");if (context == null) {return;}String text = "";if (errorCode == XGPushBaseReceiver.SUCCESS) {text = "\"" + tagName + "\"设置成功";}else {text = "\"" + tagName + "\"设置失败,错误码:" + errorCode;}Log.d(LogTag, text);//show(context, text);
    }@Overridepublic void onDeleteTagResult(Context context, int errorCode, String tagName) {KLog.i("onDeleteTagResult");if (context == null) {return;}String text = "";if (errorCode == XGPushBaseReceiver.SUCCESS) {text = "\"" + tagName + "\"删除成功";}else {text = "\"" + tagName + "\"删除失败,错误码:" + errorCode;}Log.d(LogTag, text);//show(context, text);
    }// 通知点击回调 actionType=1为该消息被清除,actionType=0为该消息被点击
    @Overridepublic void onNotifactionClickedResult(Context context, XGPushClickedResult message) {KLog.i("onNotifactionClickedResult");if (context == null || message == null) {return;}String text = "";if (message.getActionType() ==XGPushClickedResult.NOTIFACTION_CLICKED_TYPE) {// 通知在通知栏被点击啦。。。。。// APP自己处理点击的相关动作// 这个动作可以在activity的onResume也能监听,请看第3点相关内容text = "通知被打开 :" + message;KLog.i(text);KLog.i(message.getActivityName());// 获取自定义key-value,我们的app主要的根据这块的内容进行控制的,所以主要处理这块的代码String customContent = message.getCustomContent();if (!StringUtil.isEmpty(customContent)) {KLog.i("customContent", customContent);PushResult pushResult = Json.get().toObject(customContent,PushResult.class);switch (pushResult.getIndex()) { //......你的业务处理代码default:break;}}}else if (message.getActionType() ==XGPushClickedResult.NOTIFACTION_DELETED_TYPE) {// 通知被清除啦。。。。// APP自己处理通知被清除后的相关动作text = "通知被清除 :" + message;KLog.i(text);}}@Overridepublic void onRegisterResult(Context context, int errorCode, XGPushRegisterResult message) {KLog.i("onRegisterResult");// TODO Auto-generated method stubif (context == null || message == null) {return;}String text = "";if (errorCode == XGPushBaseReceiver.SUCCESS) {text = message + "注册成功";// 在这里拿tokenString token = message.getToken();}else {text = message + "注册失败,错误码:" + errorCode;}Log.d(LogTag, text);//show(context, text);
    }// 消息透传
    @Overridepublic void onTextMessage(Context context, XGPushTextMessage message) {KLog.json(Json.get().toJson(message));// TODO Auto-generated method stubString text = "收到消息:" + message.toString();// 获取自定义key-valueString customContent = message.getCustomContent();if (customContent != null && customContent.length() != 0) {try {JSONObject obj = new JSONObject(customContent);// key1为前台配置的keyif (!obj.isNull("key")) {String value = obj.getString("key");Log.d(LogTag, "get custom value:" + value);}// ...} catch (JSONException e) {e.printStackTrace();}}// APP自主处理消息的过程...
        Log.d(LogTag, text);//show(context, text);
    }
}

android app 集成 信鸽推送相关推荐

  1. java后台与android端集成信鸽推送和华为推送通道

    时间比较紧,并未调试. 需求:后端可以针对指定账号或者列表进行通知栏信息推送,优先使用华为通道.点击通知栏消息打开指定activity 后端版本V3,android sdk 3.2.7 一.后端部分代 ...

  2. android 信鸽 自动重启,Android简单集成信鸽推送

    添加项目的buid.gradle ndk { //选择要添加的对应cpu类型的.so库 abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a' // 还可以添 ...

  3. java服务端集成信鸽推送

    java服务端集成信鸽推送 最近项目需要集成推送功能,突发奇想的选了信鸽推送(可能是最近一直在用阿里的东西),没想到这坑不是一般的多,而且关于详细的集成案例,度娘上真是没一个能入眼的.算了,别的不多说 ...

  4. Android之集成极光推送

    安卓端集成极光推送是很常见的,极光推送的简单高效性适合很多想要集成推送的APP,如果你要自己装逼,也可以自己写推送,只要想做都是可以的. 第一步.Gradle配置(Module的build.gradl ...

  5. 极光推送 android 最新,Android——快速集成极光推送-Go语言中文社区

    集成极光推送 1,首先肯定是注册,添加应用 2,开始自动集成比手动集成简单第一步 在 build.gradle defaultConfig { multiDexEnabledtrue applicat ...

  6. Android之集成极光推送消息

    极光推送是为 App 提供第三方推送服务的平台之一,它提供四种消息形式: 通知 自定义消息 富媒体 本地通知 1.通知 Push Notification,即指在手机的通知栏(状态栏)上会显示的一条通 ...

  7. android 极光推送解绑,app集成极光推送笔记(angular js)

    出处:极光推送官方文档以及github上的文档 1.安装 一般使用cordova安装(其他安装方式详见文档),命令行输入: cordova plugin add jpush-phonegap-plug ...

  8. 利用信鸽推送实现Android登录后强制退出的功能(单点登录)

    首先整理思路,先思考实现逻辑: 1.集成信鸽推送 2.实现自定义推送 3.在自定义推送中,接收推送的方法内启动强制退出功能. 思路逻辑很简单,但是实现起来就得一步一步做,先集成信鸽: 这里主要是参考官 ...

  9. Java中集成极光推送实现给Android提送消息通知(附代码下载)

    场景 Android中集成极光推送实现推送消息通知与根据别名指定推送附示例代码下载: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details ...

最新文章

  1. 国庆七天学Linux技能,休闲假期不负时光
  2. VTK:Points之MaskPointsFilter
  3. php如何向数组增加数据,php向数组中增加数据的方法是什么
  4. 高级UI之Paint(滤镜,颜色通道,矩阵运算)
  5. 启动Memcached报错:/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-2.1
  6. 关于优酷开放SDk之setOnAdCountListener和setOnNetworkSppedListener
  7. wps怎么转成pdf?只需六步的转换方法
  8. matlab在振动信号处理中的应用_Matlab面向对象程序设计及其在地球物理学中的应用(4)——类的属性
  9. XRPC接口双向调用
  10. 硅谷再不是程序员们的梦想天堂了
  11. 【Flume】Flume简单介绍
  12. 数字万用表校准软件|数字万用表自动计量系统NSAT-3030
  13. 物业小区管理系统源码
  14. react js清除浏览器缓存
  15. python中reduce函数_reduce函数
  16. Excel隔行求和计算公式
  17. 【爬虫——00004】蜘蛛技能学习
  18. scp ? stall ? scp -t ? scp -f ? MTU
  19. mysql数据设置有效期_zabbix管理六之数据有效期设置
  20. 模型推荐丨政务大数据项目案例模型分享

热门文章

  1. python xlwt写入excel_python xlwt模块写入excel超过65536行报错问题解决方法
  2. 【知识星球】模型量化从1bit到8bit,二值到三值
  3. 将近400篇原创后,有三AI喊你正式加入来不来?
  4. 【AI-1000问】机器学习和模式识别是什么关系?
  5. python中requests的常用方法_python3 Requests常用操作
  6. 【BZOJ1185】【HNOI2007】最小矩形覆盖(凸包+旋转卡壳)
  7. 外媒分析:iPhone销量低于预期是中国市场疲软影响的
  8. 把玩Fedora29操作系统
  9. 利用OracleCommandBuilder实现 datatable与数据库的增删改
  10. [转载]Oracle 游标使用全解