推送:腾迅信鸽 VS Bmob
最近几天了解市场上主流的推送SDK。
腾迅信鸽
所需SDK,去官网自行下载。去下载
完整的清单文件如下:
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="你的包名" 4 android:versionCode="1" 5 android:versionName="1.0" > 6 7 <uses-sdk 8 android:minSdkVersion="8" 9 android:targetSdkVersion="19" /> 10 <!-- 【必须】 信鸽SDK所需权限 --> 11 <uses-permission android:name="android.permission.INTERNET" /> 12 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 13 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 14 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 15 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 16 <uses-permission android:name="android.permission.RESTART_PACKAGES" /> 17 <uses-permission android:name="android.permission.BROADCAST_STICKY" /> 18 <uses-permission android:name="android.permission.WRITE_SETTINGS" /> 19 <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" /> 20 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 21 <uses-permission android:name="android.permission.WAKE_LOCK" /> 22 <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> 23 <uses-permission android:name="android.permission.GET_TASKS" /> 24 <uses-permission android:name="android.permission.READ_LOGS" /> 25 <uses-permission android:name="android.permission.VIBRATE" /> 26 <!-- 【可选】 信鸽SDK所需权限 --> 27 <uses-permission android:name="android.permission.BLUETOOTH" /> 28 <uses-permission android:name="android.permission.BATTERY_STATS" /> 29 30 <application 31 android:allowBackup="true" 32 android:icon="@drawable/ic_launcher" 33 android:label="@string/app_name" 34 android:theme="@style/AppTheme" > 35 <activity 36 android:name="你的包名.MainActivity" 37 android:label="@string/app_name" > 38 <intent-filter> 39 <action android:name="android.intent.action.MAIN" /> 40 41 <category android:name="android.intent.category.LAUNCHER" /> 42 </intent-filter> 43 </activity> 44 <!-- 【必须】 信鸽receiver广播接收 --> 45 <receiver 46 android:name="com.tencent.android.tpush.XGPushReceiver" 47 android:process=":xg_service_v2" > 48 <intent-filter android:priority="0x7fffffff" > 49 50 <!-- 【必须】 信鸽SDK的内部广播 --> 51 <action android:name="com.tencent.android.tpush.action.SDK" /> 52 <action android:name="com.tencent.android.tpush.action.INTERNAL_PUSH_MESSAGE" /> 53 <!-- 【必须】 系统广播:开屏和网络切换 --> 54 <action android:name="android.intent.action.USER_PRESENT" /> 55 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> 56 57 <!-- 【可选】 一些常用的系统广播,增强信鸽service的复活机会,请根据需要选择。当然,你也可以添加APP自定义的一些广播让启动service --> 58 <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /> 59 <action android:name="android.intent.action.ACTION_POWER_CONNECTED" /> 60 <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /> 61 </intent-filter> 62 <!-- 【可选】 usb相关的系统广播,增强信鸽service的复活机会,请根据需要添加 --> 63 <intent-filter android:priority="0x7fffffff" > 64 <action android:name="android.intent.action.MEDIA_UNMOUNTED" /> 65 <action android:name="android.intent.action.MEDIA_REMOVED" /> 66 <action android:name="android.intent.action.MEDIA_CHECKING" /> 67 <action android:name="android.intent.action.MEDIA_EJECT" /> 68 69 <data android:scheme="file" /> 70 </intent-filter> 71 </receiver> 72 73 <!-- 【必须】 (2.30及以上版新增)展示通知的activity --> 74 <!-- 【注意】 如果被打开的activity是启动模式为SingleTop,SingleTask或SingleInstance,请根据通知的异常自查列表第8点处理 --> 75 <activity 76 android:name="com.tencent.android.tpush.XGPushActivity" 77 android:exported="true" > 78 <intent-filter> 79 80 <!-- 若使用AndroidStudio,请设置android:name="android.intent.action" --> 81 <action android:name="" /> 82 </intent-filter> 83 </activity> 84 85 <!-- 【必须】 信鸽service --> 86 <service 87 android:name="com.tencent.android.tpush.service.XGPushService" 88 android:exported="true" 89 android:persistent="true" 90 android:process=":xg_service_v2" /> 91 92 <!-- 【必须】 通知service,此选项有助于提高抵达率 --> 93 <service 94 android:name="com.tencent.android.tpush.rpc.XGRemoteService" 95 android:exported="true" > 96 <intent-filter> 97 <action android:name="你的包名.PUSH_ACTION" /> 98 </intent-filter> 99 </service> 100 101 <!-- 【必须】 请将YOUR_ACCESS_ID修改为APP的AccessId,“21”开头的10位数字,中间没空格 --> 102 <meta-data 103 android:name="XG_V2_ACCESS_ID" 104 android:value="你的ACCESS_ID" /> 105 <!-- 【必须】 请将YOUR_ACCESS_KEY修改为APP的AccessKey,“A”开头的12位字符串,中间没空格 --> 106 <meta-data 107 android:name="XG_V2_ACCESS_KEY" 108 android:value="你的ACCESS_KEY" /> 109 </application> 110 111 </manifest>
View Code
MainActivity中配置如下:
1 @Override 2 protected void onCreate(Bundle savedInstanceState) { 3 super.onCreate(savedInstanceState); 4 setContentView(R.layout.activity_main); 5 XGPushManager.registerPush(this); 6 // // 2.36(不包括)之前的版本需要调用以下2行代码 7 // Intent service = new Intent(this, XGPushService.class); 8 // startService(service); 9 }
View Code
相当Easy吧,如果过程无误,就可以正常推送了。
Bmob
Bmob配置过程相对信鸽来说稍微复杂一点,缺点就是需要自己在自定义Receiver里接收推送消息,自己发送通知,但可定制性也较强。
所需SDK,去官网自行下载。去下载
完整的清单文件如下:
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="你的包名" 4 android:versionCode="1" 5 android:versionName="1.0" > 6 7 <uses-sdk 8 android:minSdkVersion="8" 9 android:targetSdkVersion="19" /> 10 11 <!-- BmobPush SDK权限 --> 12 <permission 13 android:name="cn.bmob.permission.push" 14 android:protectionLevel="normal" > 15 </permission> 16 17 <uses-permission android:name="cn.bmob.permission.push" /> <!-- 添加自定义的权限 --> 18 <uses-permission android:name="android.permission.READ_LOGS" /> 19 <uses-permission android:name="android.permission.INTERNET" /> 20 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 21 <uses-permission android:name="android.permission.WAKE_LOCK" /> 22 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 23 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 24 <uses-permission android:name="android.permission.VIBRATE" /> 25 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 26 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 27 <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" /> 28 29 <application 30 android:allowBackup="true" 31 android:icon="@drawable/ic_launcher" 32 android:label="@string/app_name" 33 android:theme="@style/AppTheme" > 34 <activity 35 android:name="你的包名.MainActivity" 36 android:label="@string/app_name" 37 android:launchMode="singleTop" > 38 <intent-filter> 39 <action android:name="android.intent.action.MAIN" /> 40 41 <category android:name="android.intent.category.LAUNCHER" /> 42 </intent-filter> 43 </activity> 44 45 <service 46 android:name="cn.bmob.push.lib.service.PushService" 47 android:exported="true" 48 android:label="PushService" 49 android:permission="cn.bmob.permission.push" 50 android:process="cn.bmob.push" > 51 <intent-filter> 52 <action android:name="cn.bmob.push.lib.service.PushService" /> 53 </intent-filter> 54 </service> 55 56 <receiver android:name="cn.bmob.push.PushReceiver" > 57 <intent-filter android:priority="2147483647" > <!-- 优先级加最高 --> 58 <!-- 系统启动完成后会调用 --> 59 <action android:name="android.intent.action.BOOT_COMPLETED" /> 60 <!-- 解锁完成后会调用 --> 61 <action android:name="android.intent.action.USER_PRESENT" /> 62 <!-- 监听网络连通性 --> 63 <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> 64 </intent-filter> 65 </receiver> 66 <!-- 第四部中创建的消息接收器,在这里进行注册 --> 67 <receiver android:name="你的包名.MyPushMessageReceiver" > 68 <intent-filter> 69 <action android:name="cn.bmob.push.action.MESSAGE" /> 70 </intent-filter> 71 </receiver> 72 </application> 73 74 </manifest>
View Code
MainActivity中配置如下:
1 // 初始化BmobSDK 2 Bmob.initialize(this, "你的AppKey"); 3 // 使用推送服务时的初始化操作 4 BmobInstallation.getCurrentInstallation(this).save(); 5 // 启动推送服务 6 BmobPush.startWork(this, "你的AppKey");
View Code
MyPushMessageReceiver完整代码如下:
1 public class MyPushMessageReceiver extends BroadcastReceiver { 2 3 private Context mContext; 4 5 @Override 6 public void onReceive(Context context, Intent intent) { 7 mContext = context; 8 if (intent.getAction().equals(PushConstants.ACTION_MESSAGE)) { 9 String jsonstr = intent 10 .getStringExtra(PushConstants.EXTRA_PUSH_MESSAGE_STRING); 11 String msg = ""; 12 try { 13 JSONObject object = new JSONObject(jsonstr); 14 msg = object.getString("alert"); 15 } catch (JSONException e) { 16 e.printStackTrace(); 17 } 18 19 SendNotification(msg); 20 } 21 } 22 23 /** 24 * 发送通知 25 * 26 * @param message 27 */ 28 @SuppressWarnings("deprecation") 29 private void SendNotification(String message) { 30 // 点击之后执行的Intent 31 Intent intent = new Intent(mContext, MainActivity.class); 32 PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, 33 intent, 0); 34 Notification notification = new Notification(); 35 notification.icon = R.drawable.ic_launcher; 36 notification.tickerText = "收到消息推送"; 37 notification.when = System.currentTimeMillis(); 38 notification.defaults = Notification.DEFAULT_SOUND 39 | Notification.DEFAULT_VIBRATE;// 设置默认为系统声音 40 notification.flags = Notification.FLAG_AUTO_CANCEL;// 点击后自动消失 41 notification.setLatestEventInfo(mContext, "推送消息", message, 42 pendingIntent); 43 NotificationManager mManager = (NotificationManager) mContext 44 .getSystemService(Context.NOTIFICATION_SERVICE); 45 mManager.notify(1, notification); 46 47 } 48 }
View Code
转载于:https://www.cnblogs.com/lavalike/p/4991172.html
推送:腾迅信鸽 VS Bmob相关推荐
- 如何快速体验腾迅信鸽推送
作者:zhanhailiang 日期:2014-10-13 信鸽是什么 腾讯信鸽(XG Push)是一款专业的免费移动App推送平台,支持百亿级的通知/消息推送,秒级触达移动用户,现已全面支持Andr ...
- bmob云服务器信息推送,FAQ-Bmob后端云
Q: Bmob 平台是做什么的? A: Bmob 是多租户无模式的移动应用云服务,它可以让 android/IOS/WP 等移动开 发者无需掌握任何一门服务器开发语言(如 JAVA/PHP 等),将注 ...
- 腾讯信鸽自定义推送通知
使用信鸽的过程,感觉一路艰辛,各种坑,想必各位使用过的也是深有体会的吧.而且官方文档也太简洁了.demo功能也不全,没办法只能自己摸索着来,这不刚把自定义通知弄明白,就给各位看官献上来了. 1. XG ...
- Android集成腾讯信鸽推送SDK
推送是每个应用中常见的功能今天使用一下腾讯的信鸽推送听说信鸽推送保活率比较高~ 第一步先去官网注册账号https://xg.qq.com/推荐使用QQ直接登陆,进去之后点击"新建应用&quo ...
- 【友盟推送】与【腾讯信鸽推送】
友盟推送文档: https://developer.umeng.com/docs/66632/detail/68343#h1-u670Du52A1u7AEFu4EE3u7801u8C03u7528u7 ...
- 一篇文章带你了解APP PUSH推送机制
本文为PMCAFF专栏作者卓别木出品 写作目的: 本文主要讲解关于APP PUSH的流程.机制及相关经验,一是为了方便各位可以针对APP迅速制定PUSH消息推送方案,实现0到1的推送功能搭建,二是可以 ...
- 关于消息推送,你可以知道这个
如何给某类用户进行推送呢? 在维护Bmob消息推送SDK的时候,有很多开发者会问到如何给某类用户进行推送,例如,在教学类的应用中你需要对60分以下的同学进行推送提醒,鼓励他们努力学习.下边我就详细阐述 ...
- 2021-06-10-APP PUSH推送机制
APP PUSH推送机制 一.APP PUSH定义与价值 二.APP推送分类 三. PUSH流程 四.底层通道说明 五.下发推送 六.数据上报 七.PUSH特点 八.触达率的提升 一.APP PUSH ...
- 【转】推送消息推送机制
原文链接:推送消息&推送机制 - 知乎 消息推送(push)用一句话解释就是:服务端向客户端发送了一条消息,我们在通知栏.锁屏通知.微信消息等等之类的都是消息推送. 1/推送类型有哪些? 消息 ...
最新文章
- Delphi_01_控制台版HelloWorld
- cocos2dx - Lua 语言
- Linux C函数库参考手册
- postgresql中装gis插件_Postgresql 空间扩展需要Postgis插件
- CDN边缘JavaScript敏捷交付实践
- malloc,free,new,delete解析(原)
- python中集合用法大全_python中集合的用法
- 电脑任务管理器快捷键_电脑知识小常识
- IntelliJ IDEA for Mac如何替换文件内容中指定的关键词
- 轻松掌握IP子网划分的概念和操作方法
- 你的护城河在哪?老程序员的一些2016感悟
- linux 格式化 lvm2,fedora 23 lvm2格式 根目录磁盘空间不足 扩容方法
- 南阳理工acm,鸡兔同笼
- 《人工智能 智能系统指南》
- Windows下的发包工具推荐[Colasoft Packet Builder]含使用教程
- 怎么快速查找重复文件以及删除重复文件
- eval与assert一句话木马分析
- 一座城市靠税收能年入多少钱?
- 敏捷开发培训后的感想
- 「高频面试题」浏览器从输入url到页面展示中间发生了什么
热门文章
- Redis专题-缓存穿透、缓存雪崩、缓存击穿
- 阴阳师哪些服务器可以跨系统转移,阴阳师怎么跨系统转服?跨系统转服方法介绍...
- mfc调取摄像头显示并截图_前摄后录,让行车安全再次提升:70迈智能后视镜后摄像头体验...
- mysql的付费功能_MYSQL对游戏用户付费行为分析
- 单元格内多个姓名拆分成一列_excel单元格拆分拆分同一单元格中的姓名,原来这么简单啊!...
- 网工路由基础(3)RIP原理与配置
- 云栖收官:想跟远道而来的朋友们说
- 中小企业如何实现在家研发软件?看这个就够了
- mysql字符串函数混合使用_MySql字符串函数使用技巧
- 时间序列python复杂网络实例_基于时间序列数据的复杂网络重构