厂商推送平台 | IM 控制台配置 |
| |
厂商 | 单击后后续动作 | 应用内指定界面 |
小米 | 打开应用内指定页面 | intent:// 您配置的 hostname /您配置的 path #Intent;scheme=您配置的协议,也就是你定义的 scheme ;launchFlags=0x4000000;component=您应用跳转界面的完整类名 ;endTUIKitDemo 配置的是:intent://com.tencent.qcloud/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.main.MainActivity;end |
华为 | 打开应用内指定页面 | intent:// 您配置的 hostname /您配置的 path #Intent;scheme=您配置的协议,也就是你定义的 scheme ;launchFlags=0x4000000;component=您应用跳转界面的完整类名 ;endTUIKitDemo 配置的是:intent://com.tencent.qcloud/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.main.MainActivity;end |
魅族 | 打开应用内指定页面 | 您应用跳转界面的完整类名 TUIKitDemo 配置的是: com.tencent.qcloud.tim.demo.main.MainActivity |
OPPO | 打开应用内指定页面 | 您应用跳转界面的完整类名 TUIKitDemo 配置的是: activity:com.tencent.qcloud.tim.demo.main.MainActivity |
vivo | 打开应用内指定页面 | intent:// 您配置的 hostname /您配置的 path #Intent;scheme=您配置的协议,也就是你定义的 scheme ;launchFlags=0x4000000;component=您应用跳转界面的完整类名 ;endTUIKitDemo 配置的是:intent://com.tencent.qcloud/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.main.MainActivity;end |
Google FCM | 不需要配置 | 默认会跳转至应用的 Launcher 界面 |
<!-- TUIKitDemo 配置的跳转界面是 MainActivity,所以这里填 com.tencent.qcloud.tim.demo.main.MainActivity。集成到您的应用后,需要替换您的应用界面完整类名 --><activityandroid:name="您应用跳转界面的完整类名"android:launchMode="singleTask"android:screenOrientation="portrait"android:windowSoftInputMode="adjustResize|stateHidden"><!-- 离线推送打开应用内页面 --><intent-filter><action android:name="android.intent.a和Google FCmo配置的是:pushscheme://com.tencent.qcloud/detail --><dataandroid:host="您配置的 hostname"android:path="您配置的 path"android:scheme="您配置的协议,也就是你定义的 scheme" /></intent-filter></activity>
public class PrivateConstants {// 在腾讯云控制台上传第三方推送证书后分配的证书IDpublic static final long GOOGLE_FCM_PUSH_BUZID = 15518;}
<!-- 注意:TUIKitDemo 的 applicationId 是 com.tencent.qcloud.tim.tuikit,这里的 “xxxx” 需要替换您的应用的 applicationId。 --><!-- ********海外google云消息传递start******** --><serviceandroid:name="xxxx.GoogleFCMMsgService"android:exported="false"><intent-filter><action android:name="com.google.firebase.MESSAGING_EVENT" /></intent-filter></service><!-- ********海外google云消息传递end******** -->
dependencies {...classpath 'com.google.gms:google-services:4.2.0'}
apply plugin: 'com.google.gms.google-services'
dependencies {......// 主包implementation 'com.tencent.tpns:tpns:1.3.1.1-release'// Google FCMimplementation "com.tencent.tpns:fcm:1.3.1.1-release"// google 云消息传递implementation ('com.google.firebase:firebase-messaging:19.0.1')// 小米implementation "com.tencent.tpns:xiaomi:1.3.1.1-release"// 魅族implementation "com.tencent.tpns:meizu:1.3.1.1-release"// OPPOimplementation "com.tencent.tpns:oppo:1.3.1.1-release"// vivoimplementation "com.tencent.tpns:vivo:1.3.2.0-release"// 华为implementation 'com.tencent.tpns:huawei:1.3.1.1-release'implementation 'com.huawei.hms:push:5.0.2.300'}
public void init() {...if (BrandUtil.isBrandXiaoMi()) {// 小米离线推送MiPushClient.registerPush(this, PrivateConstants.XM_PUSH_APPID, PrivateConstants.XM_PUSH_APPKEY);} else if (BrandUtil.isBrandHuawei()) {// 华为离线推送,设置是否接收Push通知栏消息调用示例HmsMessaging.getInstance(this).turnOnPush().addOnCompleteListener(new com.huawei.hmf.tasks.OnCompleteListener<Void>() {@Overridepublic void onComplete(com.huawei.hmf.tasks.Task<Void> task) {if (task.isSuccessful()) {DemoLog.i(TAG, "huawei turnOnPush Complete");} else {DemoLog.e(TAG, "huawei turnOnPush failed: ret=" + task.getException().getMessage());}}});new Thread() {@Overridepublic void run() {try {// read from agconnect-services.jsonString appId = AGConnectServicesConfig.fromContext(MainActivity.this).getString("client/app_id");String token = HmsInstanceId.getInstance(MainActivity.this).getToken(appId, "HCM");DemoLog.i(TAG, "huawei get token:" + token);if(!TextUtils.isEmpty(token)) {// 该 token 需要保存并调用 setOfflinePushConfig 接口上报 IMSDKString token = (String) o;}} catch (ApiException e) {DemoLog.e(TAG, "huawei get token failed, " + e);}}}.start();} else if (MzSystemUtils.isBrandMeizu(this)) {// 魅族离线推送PushManager.register(this, PrivateConstants.MZ_PUSH_APPID, PrivateConstants.MZ_PUSH_APPKEY);} else if (BrandUtil.isBrandVivo()) {// vivo离线推送PushClient.getInstance(getApplicationContext()).initialize();DemoLog.i(TAG, "vivo support push: " + PushClient.getInstance(getApplicationContext()).isSupport());PushClient.getInstance(getApplicationContext()).turnOnPush(new IPushActionListener() {@Overridepublic void onStateChanged(int state) {if (state == 0) {String regId = PushClient.getInstance(getApplicationContext()).getRegId();DemoLog.i(TAG, "vivopush open vivo push success regId = " + regId);// // 该 token 需要保存并调用 setOfflinePushConfig 接口上报 IMSDKString token = (String) o;} else {// 根据vivo推送文档说明,state = 101 表示该vivo机型或者版本不支持vivo推送,链接:https://dev.vivo.com.cn/documentCenter/doc/156DemoLog.i(TAG, "vivopush open vivo push fail state = " + state);}}});} else if (HeytapPushManager.isSupportPush()) {// oppo离线推送OPPOPushImpl oppo = new OPPOPushImpl();oppo.createNotificationChannel(this);// oppo接入文档要求,应用必须要调用init(...)接口,才能执行后续操作。HeytapPushManager.init(this, false);HeytapPushManager.register(this, PrivateConstants.OPPO_PUSH_APPKEY, PrivateConstants.OPPO_PUSH_APPSECRET, oppo);} else if (BrandUtil.isGoogleServiceSupport()) {FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new com.google.android.gms.tasks.OnCompleteListener<InstanceIdResult>() {@Overridepublic void onComplete(Task<InstanceIdResult> task) {if (!task.isSuccessful()) {DemoLog.w(TAG, "getInstanceId failed exception = " + task.getException());return;}// Get new Instance ID tokenString token = task.getResult().getToken();DemoLog.i(TAG, "google fcm getToken = " + token);// 该 token 需要保存并调用 setOfflinePushConfig 接口上报 IMSDKString token = (String) o;}});}}
public class GoogleFCMMsgService extends FirebaseMessagingService {...@Overridepublic void onNewToken(String token) {DemoLog.i(TAG, "onNewToken token=" + token);// 该 token 需要保存并调用 setOfflinePushConfig 接口上报 IMSDKString pushToken = token;}...}
V2TIMOfflinePushConfig v2TIMOfflinePushConfig = null;// 需要设置 businessID 为对应厂商的证书 ID,isTPNSToken 为 false,上报注册厂商推送服务获取的 token。v2TIMOfflinePushConfig = new V2TIMOfflinePushConfig(0, token, true);V2TIMManager.getOfflinePushManager().setOfflinePushConfig(v2TIMOfflinePushConfig, new V2TIMCallback() {@Overridepublic void onError(int code, String desc) {DemoLog.d(TAG, "setOfflinePushToken err code = " + code);}@Overridepublic void onSuccess() {DemoLog.d(TAG, "setOfflinePushToken success");}});
// 应用切到后台时V2TIMManager.getOfflinePushManager().doBackground(totalCount, new V2TIMCallback() {@Overridepublic void onError(int code, String desc) {DemoLog.e(TAG, "doBackground err = " + code + ", desc = " + desc);}@Overridepublic void onSuccess() {DemoLog.i(TAG, "doBackground success");}});// 应用切回前台时V2TIMManager.getOfflinePushManager().doForeground(new V2TIMCallback() {@Overridepublic void onError(int code, String desc) {DemoLog.e(TAG, "doForeground err = " + code + ", desc = " + desc);}@Overridepublic void onSuccess() {DemoLog.i(TAG, "doForeground success");}});
OfflineMessageContainerBean containerBean = new OfflineMessageContainerBean();OfflineMessageBean entity = new OfflineMessageBean();entity.content = message.getExtra().toString();entity.sender = message.getFromUser();entity.nickname = chatInfo.getChatName();entity.faceUrl = TUIChatConfigs.getConfigs().getGeneralConfig().getUserFaceUrl();containerBean.entity = entity;V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setExt(new Gson().toJson(containerBean).getBytes());// OPPO必须设置ChannelID才可以收到推送消息,这个channelID需要和控制台一致v2TIMOfflinePushInfo.setAndroidOPPOChannelID("tuikit");final V2TIMMessage v2TIMMessage = message.getTimMessage();String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {TUIChatLog.v(TAG, "sendMessage onSuccess:" + v2TIMMessage.getMsgID());message.setMsgTime(v2TIMMessage.getTimestamp());TUIChatUtils.callbackOnSuccess(callBack, message);}});
private void handleOfflinePush() {// 根据登录状态,判断是否需要重新登录 IM// 1. 如果登录状态为 V2TIMManager.V2TIM_STATUS_LOGOUT,跳转到登录界面,重新登录 IMif (V2TIMManager.getInstance().getLoginStatus() == V2TIMManager.V2TIM_STATUS_LOGOUT) {Intent intent = new Intent(MainActivity.this, SplashActivity.class);if (getIntent() != null) {intent.putExtras(getIntent());}startActivity(intent);finish();return;}// 2. 否则,说明 App 只是处于退后台的状态,直接解析离线推送参数final OfflineMessageBean bean = OfflineMessageDispatcher.parseOfflineMessage(getIntent());if (bean != null) {setIntent(null);NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);if (manager != null) {manager.cancelAll();}if (bean.action == OfflineMessageBean.REDIRECT_ACTION_CHAT) {if (TextUtils.isEmpty(bean.sender)) {return;}TUIUtils.startChat(bean.sender, bean.nickname, bean.chatType);}}}
本页内容是否解决了您的问题?