腾讯TPNS推送
(信鸽升级版,信鸽产品已于2020.10.31彻底下线)
收费标准:
https://cloud.tencent.com/document/product/548/36648#billingmodel1
文档地址:
https://cloud.tencent.com/document/product/548/36651
快速集成:
-
新增产品
-
配置管理
-
输入包名
-
快速接入
-
按步骤操作即可
一、下载json文件放置到APP下
二、添加工程配置
1). 在项目级 build.gradle 文件中 buildscript -> dependencies 下添加以下配置
classpath “com.tencent.android.tpns:tpnsplugin:1.8.0”
在项目级 build.gradle 文件中 allprojects -> repositories 下添加以下配置
mavenCentral()
maven {url ‘http://developer.huawei.com/repo/’}
添加后效果如下:
buildscript {
repositories {
…
mavenCentral()
maven {url ‘http://developer.huawei.com/repo/’}
}
dependencies {
…
classpath “com.tencent.android.tpns:tpnsplugin:1.8.0” //tpns集成插件
}allprojects {
repositories {
…
mavenCentral()
maven {url ‘http://developer.huawei.com/repo/’} // 华为仓,如果不集成华为可以不加
}
}
2). 在应用级 build.gradle 文件中添加下方两部分配置
apply plugin: “com.tencent.android.tpns”
ndk {
//可以根据需要来自行选择并添加对应cpu类型的.so库。
abiFilters ‘armeabi’, ‘armeabi-v7a’, ‘arm64-v8a’
//还可以添加 ‘x86’, ‘x86_64’, ‘mips’, ‘mips64’
}
添加后效果如下:
apply plugin: “com.tencent.android.tpns”
android {
…
defaultConfig {
…
ndk {
//可以根据需要来自行选择并添加对应cpu类型的.so库。
abiFilters ‘armeabi’, ‘armeabi-v7a’, ‘arm64-v8a’
//还可以添加 ‘x86’, ‘x86_64’, ‘mips’, ‘mips64’
}
}
…
}
3). 点击项目右上角 [Sync Now] 同步项目
三、初始化推送服务
1). 在XGPushManager.registerPush前,开启Debug日志数据(注意:上线时请设置为false)
XGPushConfig.enableDebug(this,true);
2). 注册XGToken(根据业务场景选择调用时机)
XGPushManager.registerPush(this, new XGIOperateCallback() {
@Override
public void onSuccess(Object data, int flag) {
//token在设备卸载重装的时候有可能会变
Log.d(“TPush”, “注册成功,设备token为:” + data);
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.d("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
四、混淆配置
如果您的项目中使用 proguard 等工具,已做代码混淆,请添加以下混淆keep选项,否则将导致腾讯移动推送服务不可用:
#TPNS SDK
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep class com.tencent.android.tpush.** {;}
-keep class com.tencent.tpns.baseapi.** {;}
-keep class com.tencent.tpns.mqttchannel.** {;}
-keep class com.tencent.tpns.dataacquisition.** {;}
如果接入了厂商通道,请针对各厂商添加以下混淆keep选项:
#华为通道
-keepattributes Annotation
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.{*;}
-keep class com.huawei.updatesdk.{;}
-keep class com.huawei.hms.**{;}
-keep class com.huawei.android.hms.agent.**{*;}
#小米通道
-keep class com.xiaomi.**{*;}
-keep public class * extends com.xiaomi.mipush.sdk.PushMessageReceiver
#魅族通道
-dontwarn com.meizu.cloud.pushsdk.**
-keep class com.meizu.cloud.pushsdk.**{*;}
#OPPO通道
-keep public class * extends android.app.Service
-keep class com.heytap.mcssdk.** {*;}
-keep class com.heytap.msp.** { *;}
#VIVO通道
-dontwarn com.vivo.push.**
-keep class com.vivo.push.{*; }
-keep class com.vivo.vms.{; }
-keep class com.tencent.android.vivopush.VivoPushMessageReceiver{;}
6.点击通知跳转指定页面
1).客户端自定义(推荐)
MessageReceiver
public static final String UPDATE_LISTVIEW_ACTION = “com.example.tpnsdemo.activity.UPDATE_LISTVIEW”;
onNotificationClickedResult():
Intent intent = new Intent(UPDATE_LISTVIEW_ACTION);
intent.putExtra(“text”, message.getContent());
context.sendBroadcast(intent);
指定Activity中:
IntentFilter intentFilter = new IntentFilter(MessageReceiver.UPDATE_LISTVIEW_ACTION);
MsgReceiver msgReceiver = new MsgReceiver();
registerReceiver(msgReceiver, intentFilter);
class MsgReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (MessageReceiver.UPDATE_LISTVIEW_ACTION.equals(intent.getAction())) {
String content = intent.getStringExtra(“text”);
Log.e(“TAG”, "onReceive: " + content);
tv.setText(content);
}
}
}
主流的第三方推送平台分类
手机厂商类:
小米推送(小米http://dev.xiaomi.com/doc/?page_id=1670)
华为推送 (华为公司http://developer.huawei.com/push)
第三方平台类:
友盟推送 (友盟http://www.umeng.com/push)
极光推送 (深圳市和讯华谷信息技术有限公司https://www.jpush.cn/)
云巴(基于MQTT)深圳市微智云科技有限公司http://www.yunba.io/
BAT大厂的平台推送:
阿里云移动推送 (https://help.aliyun.com)
腾讯信鸽推送(腾讯公司http://xg.qq.com/)
百度云推送(百度http://developer.baidu.com/cloud/push)
具体选择方案:
DEMO地址(tpns推送)
https://download.csdn.net/download/tong_csdn/22714701