最近几天了解市场上主流的推送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>

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. }

相当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>

MainActivity中配置如下:

  1. // 初始化BmobSDK
  2. Bmob.initialize(this, "你的AppKey");
  3. // 使用推送服务时的初始化操作
  4. BmobInstallation.getCurrentInstallation(this).save();
  5. // 启动推送服务
  6. BmobPush.startWork(this, "你的AppKey");

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. }

推送:腾迅信鸽 VS Bmob的更多相关文章

  1. QtAndroid具体解释(6):集成信鸽推送

    推送是我们开发移动应用经经常使用到的功能,Qt on Android 应用也会用到,之前也有朋友问过,这次我们来看看怎么在 Qt on Android 应用中来集成来自腾讯的信鸽推送. 有关信鸽的 S ...

  2. 信鸽推送 10004,os文件配置出错,解决办法

    信鸽推送注册失败 返回码 10004 是 os  配置出现问题 经过询问客服,得到以下解决办法 将SDK中的so文件复制下来 新建文件夹jniLibs,并将 so 配置文件粘贴进去 便可完成注册

  3. 信鸽推送 .NET (C#) 服务端 SDK rest api 调用库(v1.2)

    信鸽推送 .NET  服务端 SDK rest api 调用库-介绍 该版本是基于信鸽推送v2版本的时候封装的,先拿出来与大家分享,封装还还凑合,不依赖其他http调用件,唯一依赖json序列化dll ...

  4. 信鸽推送(XGPush)

    先放入两个链接: iOS信鸽接入官方文档:http://developer.qq.com/wiki/xg/iOS接入/iOS%20SDK完整接入/iOS%20SDK完整接入.html 信鸽开放平台:h ...

  5. 腾讯信鸽推送Android SDK快速指南

    信鸽Android SDK是一个能够提供Push服务的开发平台,提供给开发者简便.易用的API接口,方便快速接入.目前支持Android 2.2及以上版本系统.本文档将引导用户以最快的速度嵌入信鸽SD ...

  6. 信鸽推送.NET SDK 开源

    github 地址 https://github.com/yeanzhi/XinGePushSDK.NET 传送门如何安装    建议使用nuget安装包,搜索"信鸽"即可    ...

  7. Android 信鸽推送通知栏不显示推送的通知

    使用信鸽推送,却怎么也没反应.经过查看log发现确实是收到了推送过来的消息了,其中有这么一行: W/dalvikvm(23255): VFY: unable to resolve virtual me ...

  8. android app 集成 信鸽推送

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

  9. QQ信鸽推送

    闲来无事,看看腾讯的信鸽推送! 优点: 1.毕竟大腿出的东西,不会太差 2.集成快 3.推送效率高,功能强,APP后台被杀的情况下同样能接受到推送. 废话少说,直接上代码: 源代码.zip

随机推荐

  1. 应用SecureCRT(发送接收文件)

    使用 SecureCRT 和 cz. sz,可以从 Linux 服务器上下载/上传文件. Linux 上要安装 lszrz 包 (1)编译安装root 账号登陆后,依次执行以下命令 cd /tmp w ...

  2. DaoImpl中实现查询分页-使用HibernateCallback来做更加方便

    /** * */ package com.wolfgang.dao; import java.sql.SQLException; import java.util.List; import org.h ...

  3. BZOJ 3196 二逼平衡树

    Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询k在区间内的 ...

  4. Unity3d IOS中的IGUI控件

    Unity3d IOS中的IGUI控件 @灰太龙  群63438968 我讲一下IOS中用的UI,我们采用IGUI,需要使用IGUI的高版本,在Unity3d 4.2中也可以使用的! 之前IGUI有个 ...

  5. tortoisegit安装使用

    git的使用越来越广泛 使用命令比较麻烦,下面讲解一下tortoisegit的使用 先下载安装git(msysgit)和tortoisegit,安装后提示重启电脑,不解释 1.找一个文件夹做仓库 这里 ...

  6. InstallShield limited edition 生成单个 setup.exe 安装文件

    1.vs里选中当前Setup项目, 2.在vs工具栏中"配置管理器"的下拉列表里,把"Debug"改为"SingleImage" 3.重新编 ...

  7. 【HDOJ】4704 Sum

    数学题.f(n) = 2^(n-1) mod (1e9+7). #include <cstdio> #define MAXN 100005 char buf[MAXN]; __int64 ...

  8. open和fopen的区别(转)

    转载自:http://www.cnblogs.com/joeblackzqq/archive/2011/04/11/2013010.html open和fopen的区别: 1.缓冲文件系统缓 冲文件系 ...

  9. 查错 CH Round #57 - Story of the OI Class

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/查错 题解:刚开始看见立马以为是 ...

  10. 数据结构(主席树):HDU 5654 xiaoxin and his watermelon candy

    Problem Description During his six grade summer vacation, xiaoxin got lots of watermelon candies fro ...