推送:腾迅信鸽 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
随机推荐
- 应用SecureCRT(发送接收文件)
使用 SecureCRT 和 cz. sz,可以从 Linux 服务器上下载/上传文件. Linux 上要安装 lszrz 包 (1)编译安装root 账号登陆后,依次执行以下命令 cd /tmp w ...
- DaoImpl中实现查询分页-使用HibernateCallback来做更加方便
/** * */ package com.wolfgang.dao; import java.sql.SQLException; import java.util.List; import org.h ...
- BZOJ 3196 二逼平衡树
Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询k在区间内的 ...
- Unity3d IOS中的IGUI控件
Unity3d IOS中的IGUI控件 @灰太龙 群63438968 我讲一下IOS中用的UI,我们采用IGUI,需要使用IGUI的高版本,在Unity3d 4.2中也可以使用的! 之前IGUI有个 ...
- tortoisegit安装使用
git的使用越来越广泛 使用命令比较麻烦,下面讲解一下tortoisegit的使用 先下载安装git(msysgit)和tortoisegit,安装后提示重启电脑,不解释 1.找一个文件夹做仓库 这里 ...
- InstallShield limited edition 生成单个 setup.exe 安装文件
1.vs里选中当前Setup项目, 2.在vs工具栏中"配置管理器"的下拉列表里,把"Debug"改为"SingleImage" 3.重新编 ...
- 【HDOJ】4704 Sum
数学题.f(n) = 2^(n-1) mod (1e9+7). #include <cstdio> #define MAXN 100005 char buf[MAXN]; __int64 ...
- open和fopen的区别(转)
转载自:http://www.cnblogs.com/joeblackzqq/archive/2011/04/11/2013010.html open和fopen的区别: 1.缓冲文件系统缓 冲文件系 ...
- 查错 CH Round #57 - Story of the OI Class
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/查错 题解:刚开始看见立马以为是 ...
- 数据结构(主席树):HDU 5654 xiaoxin and his watermelon candy
Problem Description During his six grade summer vacation, xiaoxin got lots of watermelon candies fro ...