2021-09-14

腾讯TPNS推送
(信鸽升级版,信鸽产品已于2020.10.31彻底下线)
收费标准:
https://cloud.tencent.com/document/product/548/36648#billingmodel1
文档地址:
https://cloud.tencent.com/document/product/548/36651
快速集成:

  1. 新增产品

  2. 配置管理
    在这里插入图片描述

  3. 输入包名
    在这里插入图片描述

  4. 快速接入
    在这里插入图片描述

  5. 按步骤操作即可
    在这里插入图片描述
    一、下载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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值