推送:腾迅信鸽 VS Bmob
最近几天了解市场上主流的推送SDK。
腾迅信鸽
所需SDK,去官网自行下载。去下载

完整的清单文件如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="你的包名"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<!-- 【必须】 信鸽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" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="你的包名.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 【必须】 信鸽receiver广播接收 -->
<receiver
android: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.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <!-- 【可选】 一些常用的系统广播,增强信鸽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> <!-- 【必须】 (2.30及以上版新增)展示通知的activity -->
<!-- 【注意】 如果被打开的activity是启动模式为SingleTop,SingleTask或SingleInstance,请根据通知的异常自查列表第8点处理 -->
<activity
android:name="com.tencent.android.tpush.XGPushActivity"
android:exported="true" >
<intent-filter> <!-- 若使用AndroidStudio,请设置android:name="android.intent.action" -->
<action android:name="" />
</intent-filter>
</activity> <!-- 【必须】 信鸽service -->
<service
android:name="com.tencent.android.tpush.service.XGPushService"
android:exported="true"
android:persistent="true"
android:process=":xg_service_v2" /> <!-- 【必须】 通知service,此选项有助于提高抵达率 -->
<service
android:name="com.tencent.android.tpush.rpc.XGRemoteService"
android:exported="true" >
<intent-filter>
<action android:name="你的包名.PUSH_ACTION" />
</intent-filter>
</service> <!-- 【必须】 请将YOUR_ACCESS_ID修改为APP的AccessId,“21”开头的10位数字,中间没空格 -->
<meta-data
android:name="XG_V2_ACCESS_ID"
android:value="你的ACCESS_ID" />
<!-- 【必须】 请将YOUR_ACCESS_KEY修改为APP的AccessKey,“A”开头的12位字符串,中间没空格 -->
<meta-data
android:name="XG_V2_ACCESS_KEY"
android:value="你的ACCESS_KEY" />
</application> </manifest>
MainActivity中配置如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
XGPushManager.registerPush(this);
// // 2.36(不包括)之前的版本需要调用以下2行代码
// Intent service = new Intent(this, XGPushService.class);
// startService(service);
}
相当Easy吧,如果过程无误,就可以正常推送了。
Bmob
Bmob配置过程相对信鸽来说稍微复杂一点,缺点就是需要自己在自定义Receiver里接收推送消息,自己发送通知,但可定制性也较强。
所需SDK,去官网自行下载。去下载

完整的清单文件如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="你的包名"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" /> <!-- BmobPush SDK权限 -->
<permission
android:name="cn.bmob.permission.push"
android:protectionLevel="normal" >
</permission> <uses-permission android:name="cn.bmob.permission.push" /> <!-- 添加自定义的权限 -->
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="你的包名.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <service
android:name="cn.bmob.push.lib.service.PushService"
android:exported="true"
android:label="PushService"
android:permission="cn.bmob.permission.push"
android:process="cn.bmob.push" >
<intent-filter>
<action android:name="cn.bmob.push.lib.service.PushService" />
</intent-filter>
</service> <receiver android:name="cn.bmob.push.PushReceiver" >
<intent-filter android:priority="2147483647" > <!-- 优先级加最高 -->
<!-- 系统启动完成后会调用 -->
<action android:name="android.intent.action.BOOT_COMPLETED" />
<!-- 解锁完成后会调用 -->
<action android:name="android.intent.action.USER_PRESENT" />
<!-- 监听网络连通性 -->
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<!-- 第四部中创建的消息接收器,在这里进行注册 -->
<receiver android:name="你的包名.MyPushMessageReceiver" >
<intent-filter>
<action android:name="cn.bmob.push.action.MESSAGE" />
</intent-filter>
</receiver>
</application> </manifest>
MainActivity中配置如下:
// 初始化BmobSDK
Bmob.initialize(this, "你的AppKey");
// 使用推送服务时的初始化操作
BmobInstallation.getCurrentInstallation(this).save();
// 启动推送服务
BmobPush.startWork(this, "你的AppKey");
MyPushMessageReceiver完整代码如下:
public class MyPushMessageReceiver extends BroadcastReceiver {
private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
if (intent.getAction().equals(PushConstants.ACTION_MESSAGE)) {
String jsonstr = intent
.getStringExtra(PushConstants.EXTRA_PUSH_MESSAGE_STRING);
String msg = "";
try {
JSONObject object = new JSONObject(jsonstr);
msg = object.getString("alert");
} catch (JSONException e) {
e.printStackTrace();
}
SendNotification(msg);
}
}
/**
* 发送通知
*
* @param message
*/
@SuppressWarnings("deprecation")
private void SendNotification(String message) {
// 点击之后执行的Intent
Intent intent = new Intent(mContext, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0,
intent, 0);
Notification notification = new Notification();
notification.icon = R.drawable.ic_launcher;
notification.tickerText = "收到消息推送";
notification.when = System.currentTimeMillis();
notification.defaults = Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE;// 设置默认为系统声音
notification.flags = Notification.FLAG_AUTO_CANCEL;// 点击后自动消失
notification.setLatestEventInfo(mContext, "推送消息", message,
pendingIntent);
NotificationManager mManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
mManager.notify(1, notification);
}
}
推送:腾迅信鸽 VS Bmob的更多相关文章
- QtAndroid具体解释(6):集成信鸽推送
推送是我们开发移动应用经经常使用到的功能,Qt on Android 应用也会用到,之前也有朋友问过,这次我们来看看怎么在 Qt on Android 应用中来集成来自腾讯的信鸽推送. 有关信鸽的 S ...
- 信鸽推送 10004,os文件配置出错,解决办法
信鸽推送注册失败 返回码 10004 是 os 配置出现问题 经过询问客服,得到以下解决办法 将SDK中的so文件复制下来 新建文件夹jniLibs,并将 so 配置文件粘贴进去 便可完成注册
- 信鸽推送 .NET (C#) 服务端 SDK rest api 调用库(v1.2)
信鸽推送 .NET 服务端 SDK rest api 调用库-介绍 该版本是基于信鸽推送v2版本的时候封装的,先拿出来与大家分享,封装还还凑合,不依赖其他http调用件,唯一依赖json序列化dll ...
- 信鸽推送(XGPush)
先放入两个链接: iOS信鸽接入官方文档:http://developer.qq.com/wiki/xg/iOS接入/iOS%20SDK完整接入/iOS%20SDK完整接入.html 信鸽开放平台:h ...
- 腾讯信鸽推送Android SDK快速指南
信鸽Android SDK是一个能够提供Push服务的开发平台,提供给开发者简便.易用的API接口,方便快速接入.目前支持Android 2.2及以上版本系统.本文档将引导用户以最快的速度嵌入信鸽SD ...
- 信鸽推送.NET SDK 开源
github 地址 https://github.com/yeanzhi/XinGePushSDK.NET 传送门如何安装 建议使用nuget安装包,搜索"信鸽"即可 ...
- Android 信鸽推送通知栏不显示推送的通知
使用信鸽推送,却怎么也没反应.经过查看log发现确实是收到了推送过来的消息了,其中有这么一行: W/dalvikvm(23255): VFY: unable to resolve virtual me ...
- android app 集成 信鸽推送
推送其实挺中意小米推送的,并经用户群占比还是比较大的,奈何拗不过php后端哥们的选型,就只好用信鸽推送了,期间接入过程中也是遇到不少问题,所以记录下来,以后如果还是用信鸽推送的话,估计看看以前的博客, ...
- QQ信鸽推送
闲来无事,看看腾讯的信鸽推送! 优点: 1.毕竟大腿出的东西,不会太差 2.集成快 3.推送效率高,功能强,APP后台被杀的情况下同样能接受到推送. 废话少说,直接上代码: 源代码.zip
随机推荐
- hadoop 异常 datanode未启动
暴力方法:(本人是学习阶段,实际工作中不能这么做)在各个节点上执行如下操作. 将/tmp 删除 将 conf/mapred-site.xml <property> <name> ...
- PLSQL 看连接数据库的用户
1. PLSQL选用SYSDBA登录,用户sys,密码xxx 2. 登录后,点tools菜单有sessions子菜单, 3.点击sessions子菜单,可以看到连接用户
- My ECMAScript 7 wishlist
With ECMAScript 6 now feature complete, any further changes to the core of JavaScript will happen in ...
- 互联网组织的未来:剖析GitHub员工的任性之源
转自:http://www.php100.com/html/it/hulianwang/2015/0108/8304.html [导读] 本文为大家介绍了著名代码托管服务商GitHub的组织运转结构. ...
- Search Insert Position——LeetCode
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- 【转】Ansys 13.0 flexlm not running完美解决方案
http://jingyan.baidu.com/article/af9f5a2dd9843a43150a4550.html 实测,12.1 用此方法问题同样得解.
- HDU4099 Revenge of Fibonacci(高精度+Trie)
Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 204800/204800 K (Java/ ...
- python关键字、转义符和字符串格式化
最近在学learn python the hard way,学习到第37章,进行了关于关键字.转义符和字符串格式化的总结.看手头上的中文版没有及时更新.于是就把这些翻译过来,以作查阅. 关键字: 关键 ...
- python 代码格式化工具:pep8ify
资料: https://github.com/spulec/pep8ify 安装 $ pip install pep8ify 用法 Usage: 2to3 [options] file|dir ... ...
- VC++ 动态检测串口的热插拔(一)通过注册表实现
在上一篇文章中讲述了如何通过循环遍历的方法获取可用串口,可是这样的方法过于暴力,难免会想有没有其他的办法那,嘿嘿,那是肯定会有的,不管什么问题,解决问题的方法永远都不止一种.下面讲述如何通过注册表来获 ...