Vendor Push Platform | Configuring in the IM console |
![]() | ![]() |
Vendor Push Platform | Configuring in the IM console |
![]() | ![]() Notes: Client ID corresponds to AppID, Client Secret corresponds to AppSecret. |
Vendor Push Platform | Configuring in the IM console |
![]() | ![]() |
Vendor Push Platform | Configuring in the IM console |
![]() | ![]() |
Vendor Push Platform | Configuring in the IM console |
![]() | ![]() |
Vendor Push Platform | Configuring in the IM console |
![]() | ![]() |
Vendor Push Platform | Configuring in the IM console |
![]() | ![]() |
Vendor | Action after Click | Specified In-app Page |
Mi | Open the specified in-app page | intent:// your hostname /your path #Intent;scheme=your protocol, that is, the scheme you defined ;launchFlags=0x4000000;component=complete class name of the page to which your app is to be redirected ;endTUIKit demo configuration: intent://com.tencent.qcloud/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.main.MainActivity;end |
Huawei | Open the specified in-app page | intent:// your hostname /your path #Intent;scheme=your protocol, that is, the scheme you defined ;launchFlags=0x4000000;component=complete class name of the page to which your app is to be redirected ;endTUIKit demo configuration: intent://com.tencent.qcloud/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.main.MainActivity;end |
HONOR | Open the specified in-app page | intent:// your hostname /your path #Intent;scheme=your protocol, that is, the scheme you defined ;launchFlags=0x4000000;component=complete class name of the page to which your app is to be redirected ;endTUIKit demo configuration: intent://com.tencent.qcloud/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.main.MainActivity;end |
Meizu | Open the specified in-app page | Complete class name of the page to which your app is to be redirectedTUIKit demo configuration: com.tencent.qcloud.tim.demo.main.MainActivity |
OPPO | Open the specified in-app page | Complete class name of the page to which your app is to be redirectedTUIKit demo configuration: activity: com.tencent.qcloud.tim.demo.main.MainActivity |
vivo | Open the specified in-app page | intent:// your hostname /your path #Intent;scheme=your protocol, that is, the scheme you defined ;launchFlags=0x4000000;component=complete class name of the page to which your app is to be redirected ;endTUIKit demo configuration: 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 | No need to configure | Redirect to the Launcher page of the app by default |
<!-- The jump interface configured by TUIKitDemo is MainActivity, so fill in com.tencent.qcloud.tim.demo.main.MainActivity here. After integrating into your application, you need to replace it with the complete class name of your application's interface. --><activityandroid:name="Complete class name of the page to which your app is to be redirected"android:launchMode="singleTask"android:screenOrientation="portrait"android:windowSoftInputMode="adjustResize|stateHidden"><!-- Open in-app page for offline push --><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><!-- TUIKitDemo is configured as: pushscheme://com.tencent.qcloud/detail --><dataandroid:host="Your hostname"android:path="Your path"android:scheme="Your protocol, i.e., the scheme you defined" /></intent-filter></activity>
public class PrivateConstants {/****** Mi offline push parameters start ******/// Certificate ID generated after uploading a third-party push certificate in the Tencent Cloud consolepublic static final long XM_PUSH_BUZID = ID of the certificate assigned to your application// `APPID` and `APPKEY` assigned by the Mi open platformpublic static final String XM_PUSH_APPID = "`APPID` of the certificate assigned to your application";public static final String XM_PUSH_APPKEY = "`APPKEY` of the certificate assigned to your application";/****** Mi offline push parameters end ******/}
<!-- Note: The applicationId of TUIKitDemo is com.tencent.qcloud.tim.tuikit. The "xxxx" here needs to be replaced with the applicationId of your application. --><!-- ********Mi Push Permission Settings******** --><permissionandroid:name="xxxx.permission.MIPUSH_RECEIVE"android:protectionLevel="signature" /><uses-permission android:name="xxxx.permission.MIPUSH_RECEIVE" /><!-- ********Mi Push service and receiver settings start******** --><serviceandroid:name="com.xiaomi.push.service.XMPushService"android:enabled="true"android:process=":pushservice" /><serviceandroid:name="com.xiaomi.push.service.XMJobService"android:enabled="true"android:exported="false"android:permission="android.permission.BIND_JOB_SERVICE"android:process=":pushservice" /><!-- Note: This service must be included in version 3.0.1 and later (including version 3.0.1) --><serviceandroid:name="com.xiaomi.mipush.sdk.PushMessageHandler"android:enabled="true"android:exported="true" /><serviceandroid:name="com.xiaomi.mipush.sdk.MessageHandleService"android:enabled="true" /><!-- Note: This service must be included in version 2.2.5 and later (including version 2.2.5) --><receiverandroid:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver"android:exported="false"><intent-filter><action android:name="android.net.conn.CONNECTIVITY_CHANGE" /><category android:name="android.intent.category.DEFAULT" /></intent-filter></receiver><receiverandroid:name="com.xiaomi.push.service.receivers.PingReceiver"android:exported="false"android:process=":pushservice"><intent-filter><action android:name="com.xiaomi.push.PING_TIMER" /></intent-filter></receiver><!-- Self-implement MI push reception broadcast --><receiverandroid:name="xxxx.XiaomiMsgReceiver"android:exported="true"><intent-filter><action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" /></intent-filter><intent-filter><action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" /></intent-filter><intent-filter><action android:name="com.xiaomi.mipush.ERROR" /></intent-filter></receiver><!-- ********Mi Push service and receiver settings end******** -->
<!-- Note: The applicationId of TUIKitDemo is com.tencent.qcloud.tim.tuikit. The "xxxx" here needs to be replaced with the applicationId of your application. --><!-- ********Huawei Push Permission Settings******** --><permissionandroid:name="xxxx.permission.PROCESS_PUSH_MSG"android:protectionLevel="signatureOrSystem" /><uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE" /><uses-permission android:name="xxxx.permission.PROCESS_PUSH_MSG" /><!-- ********Huawei Push Settings start******** --><serviceandroid:name="xxxx.HUAWEIHmsMessageService"android:exported="false"><intent-filter><action android:name="com.huawei.push.action.MESSAGING_EVENT"/></intent-filter></service><!-- ********Huawei Push Settings end******** -->
<!-- ********HONOR Push Settings start******** --><serviceandroid:name="xxxx.MyHonorMessageService"android:exported="false"><intent-filter><action android:name="com.hihonor.push.action.MESSAGING_EVENT" /></intent-filter></service><!-- ********HONOR Push Settings end******** -->
<!-- ********OPPO Push Permission Settings******** --><uses-permission android:name="com.coloros.mcs.permission.RECIEVE_MCS_MESSAGE" /><uses-permission android:name="com.heytap.mcs.permission.RECIEVE_MCS_MESSAGE" /><!-- ********OPPO Push start******** --><serviceandroid:name="com.heytap.msp.push.service.CompatibleDataMessageCallbackService"android:permission="com.coloros.mcs.permission.SEND_MCS_MESSAGE"><intent-filter><action android:name="com.coloros.mcs.action.RECEIVE_MCS_MESSAGE" /></intent-filter></service><!-- Compatible with versions below Q --><serviceandroid:name="com.heytap.msp.push.service.DataMessageCallbackService"android:permission="com.heytap.mcs.permission.SEND_PUSH_MESSAGE"><intent-filter><action android:name="com.heytap.mcs.action.RECEIVE_MCS_MESSAGE" /><action android:name="com.heytap.msp.push.RECEIVE_MCS_MESSAGE" /></intent-filter></service><!-- Compatible with Q version --><!-- ********OPPO Push end******** -->
<!-- ********vivo Push Settings start******** --><serviceandroid:name="com.vivo.push.sdk.service.CommandClientService"android:exported="true" /><activityandroid:name="com.vivo.push.sdk.LinkProxyClientActivity"android:exported="false"android:screenOrientation="portrait"android:theme="@android:style/Theme.Translucent.NoTitleBar" /><!-- push application defines message receiver declaration --><receiver android:name="xxxx.VIVOPushMessageReceiverImpl"><intent-filter><!-- receive push message --><action android:name="com.vivo.pushclient.action.RECEIVE" /></intent-filter></receiver><!-- ********vivo Push Settings end******** -->
<!-- Note: The applicationId of TUIKitDemo is com.tencent.qcloud.tim.tuikit. The "xxxx" here needs to be replaced with the applicationId of your application. --><!-- Compatible with Flyme 3.0 configuration permissions --><permissionandroid:name="xxxx.permission.C2D_MESSAGE"android:protectionLevel="signature" /><uses-permission android:name="com.meizu.c2dm.permission.RECEIVE" /><uses-permission android:name="xxxx.permission.C2D_MESSAGE" /><!-- ********Meizu Push Settings start******** --><receiver android:name="xxxx.MEIZUPushReceiver"><intent-filter><!-- receive push message --><action android:name="com.meizu.flyme.push.intent.MESSAGE" /><!-- receive register message --><action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK" /><!-- receive unregister message --><action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK" /><!-- Compatible with lower version Flyme 3 push service configuration --><action android:name="com.meizu.c2dm.intent.REGISTRATION" /><action android:name="com.meizu.c2dm.intent.RECEIVE" /><category android:name="com.tencent.qcloud.tim.demo.thirdpush" /></intent-filter></receiver><!-- ********Meizu Push Settings end******** -->
<!-- Note: The applicationId of TUIKitDemo is com.tencent.qcloud.tim.tuikit. The "xxxx" here needs to be replaced with the applicationId of your application. --><!-- ********Overseas Google Cloud Messaging start******** --><serviceandroid:name="xxxx.GoogleFCMMsgService"android:exported="false"><intent-filter><action android:name="com.google.firebase.MESSAGING_EVENT" /></intent-filter></service><!-- ********Overseas Google Cloud Messaging end******** -->
android {...defaultConfig {...manifestPlaceholders = ["VIVO_APPKEY" : "`APPKEY` of the certificate assigned to your application","VIVO_APPID" : "`APPID` of the certificate assigned to your application""HONOR_APPID" : "`APPID` of the certificate assigned to your application"]}}
// vivo begin<receiver android:name="com.tencent.qcloud.tim.demo.thirdpush.VIVOPushMessageReceiverImpl"><intent-filter><!-- receive push message --><action android:name="com.vivo.pushclient.action.RECEIVE" /></intent-filter></receiver><meta-data tools:replace="android:value"android:name="com.vivo.push.api_key"android:value="`APPKEY` of the certificate assigned to your application" /><meta-data tools:replace="android:value"android:name="com.vivo.push.app_id"android:value="`APPID` of the certificate assigned to your application" />// vivo end// honor begin<serviceandroid:name="com.tencent.qcloud.tim.tuiofflinepush.oempush.MyHonorMessageService"android:exported="false"><intent-filter><action android:name="com.hihonor.push.action.MESSAGING_EVENT" /></intent-filter></service><meta-data tools:replace="android:value"android:name="com.hihonor.push.app_id"android:value="`APPID` of the certificate assigned to your application" />// honor end
Huawei | Google FCM |
![]() | ![]() |
classpath 'com.google.gms:google-services:4.2.0'classpath 'com.huawei.agconnect:agcp:1.4.1.300'
mavenCentral()// Configure the Maven repository address for HMS Core SDK.maven {url 'https://developer.huawei.com/repo/'}
repositories {...// Configure the Maven repository address for HMS Core SDK.maven {url 'https://developer.huawei.com/repo/'}}dependencies {...classpath 'com.google.gms:google-services:4.2.0'classpath 'com.huawei.agconnect:agcp:1.4.1.300'}
apply plugin: 'com.google.gms.google-services'apply plugin: 'com.huawei.agconnect'
dependencies {......// Huaweiimplementation 'com.tencent.timpush:huawei:7.7.5282'// Google FCMimplementation 'com.tencent.timpush:fcm:7.7.5282'// Miimplementation 'com.tencent.timpush:xiaomi:7.7.5282'// OPPOimplementation 'com.tencent.timpush:oppo:7.7.5282'// vivoimplementation 'com.tencent.timpush:vivo:7.7.5282'// honorimplementation 'com.tencent.timpush:honor:7.7.5282'// Meizuimplementation 'com.tencent.timpush:meizu:7.7.5282'}
package xxx.xxx.xxx;import android.content.Context;import android.text.TextUtils;import com.tencent.qcloud.tim.tuiofflinepush.utils.TUIOfflinePushErrorBean;import android.util.Log;import com.xiaomi.mipush.sdk.ErrorCode;import com.xiaomi.mipush.sdk.MiPushClient;import com.xiaomi.mipush.sdk.MiPushCommandMessage;import com.xiaomi.mipush.sdk.MiPushMessage;import com.xiaomi.mipush.sdk.PushMessageReceiver;import java.util.List;import java.util.Map;public class XiaomiMsgReceiver extends PushMessageReceiver {private static final String TAG = XiaomiMsgReceiver.class.getSimpleName();private String mRegId;@Overridepublic void onReceivePassThroughMessage(Context context, MiPushMessage miPushMessage) {Log.d(TAG, "onReceivePassThroughMessage is called. ");}@Overridepublic void onNotificationMessageClicked(Context context, MiPushMessage miPushMessage) {Log.d(TAG, "onNotificationMessageClicked miPushMessage " + miPushMessage.toString());if (OEMPushSetting.mPushCallback == null) {return;}Map<String, String> extra = miPushMessage.getExtra();String ext = extra.get("ext");if (TextUtils.isEmpty(ext)) {Log.w(TAG, "onNotificationMessageClicked: no extra data found");return;}// When "Open Application" is selected in the IM console, clicking the notification bar will trigger this callback}@Overridepublic void onNotificationMessageArrived(Context context, MiPushMessage miPushMessage) {Log.d(TAG, "onNotificationMessageArrived is called. ");}@Overridepublic void onReceiveRegisterResult(Context context, MiPushCommandMessage miPushCommandMessage) {Log.d(TAG, "onReceiveRegisterResult is called. " + miPushCommandMessage.toString());String command = miPushCommandMessage.getCommand();List<String> arguments = miPushCommandMessage.getCommandArguments();String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);Log.d(TAG,"cmd: " + command + " | arg: " + cmdArg1 + " | result: " + miPushCommandMessage.getResultCode() + " | reason: " + miPushCommandMessage.getReason());if (MiPushClient.COMMAND_REGISTER.equals(command)) {if (miPushCommandMessage.getResultCode() == ErrorCode.SUCCESS) {mRegId = cmdArg1;}}Log.d(TAG, "regId: " + mRegId);// Call the API to report to the IM backend after obtaining the token}@Overridepublic void onCommandResult(Context context, MiPushCommandMessage miPushCommandMessage) {super.onCommandResult(context, miPushCommandMessage);}}
package xxx.xxx.xxx;import com.huawei.hms.push.HmsMessageService;import com.huawei.hms.push.RemoteMessage;import com.tencent.qcloud.tim.tuiofflinepush.TUIOfflinePushConfig;import com.tencent.qcloud.tim.tuiofflinepush.utils.TUIOfflinePushErrorBean;import android.util.Log;public class HUAWEIHmsMessageService extends HmsMessageService {private static final String TAG = HUAWEIHmsMessageService.class.getSimpleName();@Overridepublic void onMessageReceived(RemoteMessage message) {Log.i(TAG, "onMessageReceived message=" + message);}@Overridepublic void onMessageSent(String msgId) {Log.i(TAG, "onMessageSent msgId=" + msgId);}@Overridepublic void onSendError(String msgId, Exception exception) {Log.i(TAG, "onSendError msgId=" + msgId);}@Overridepublic void onNewToken(String token) {Log.i(TAG, "onNewToken token=" + token);// Call the API to report to the IM backend after obtaining the token}@Overridepublic void onTokenError(Exception exception) {Log.i(TAG, "onTokenError exception=" + exception);}@Overridepublic void onMessageDelivered(String msgId, Exception exception) {Log.i(TAG, "onMessageDelivered msgId=" + msgId);}}
package xxx.xxx.xxx;import android.text.TextUtils;import com.hihonor.push.sdk.HonorMessageService;import com.hihonor.push.sdk.bean.DataMessage;import android.util.Log;public class MyHonorMessageService extends HonorMessageService {private static final String TAG = MyHonorMessageService.class.getSimpleName();@Overridepublic void onNewToken(String token) {Log.i(TAG, "onNewToken token=" + token);if (TextUtils.isEmpty(token)) {return;}// Call the API to report to the IM backend after obtaining the token}@Overridepublic void onMessageReceived(DataMessage dataMessage) {Log.i(TAG, "onMessageReceived message=" + dataMessage);}}
package xxx.xxx.xxx;import android.app.NotificationChannel;import android.app.NotificationManager;import android.content.Context;import android.os.Build;import com.heytap.msp.push.callback.ICallBackResultService;import com.tencent.qcloud.tim.tuiofflinepush.utils.TUIOfflinePushErrorBean;import android.util.Log;public class OPPOPushImpl implements ICallBackResultService {private static final String TAG = OPPOPushImpl.class.getSimpleName();@Overridepublic void onRegister(int responseCode, String registerID) {Log.i(TAG, "onRegister responseCode: " + responseCode + " registerID: " + registerID);if (responseCode != 0) {// Print error} else {// Call the API to report to the IM backend after obtaining the token}}@Overridepublic void onUnRegister(int responseCode) {Log.i(TAG, "onUnRegister responseCode: " + responseCode);}@Overridepublic void onSetPushTime(int responseCode, String s) {Log.i(TAG, "onSetPushTime responseCode: " + responseCode + " s: " + s);}@Overridepublic void onGetPushStatus(int responseCode, int status) {Log.i(TAG, "onGetPushStatus responseCode: " + responseCode + " status: " + status);}@Overridepublic void onGetNotificationStatus(int responseCode, int status) {Log.i(TAG, "onGetNotificationStatus responseCode: " + responseCode + " status: " + status);}@Overridepublic void onError(int i, String s) {Log.i(TAG, "onError code: " + i + " string: " + s);}}
package xxx.xxx.xxx;import android.content.Context;import android.util.Log;import com.vivo.push.model.UPSNotificationMessage;import com.vivo.push.sdk.OpenClientPushMessageReceiver;import java.util.Map;public class VIVOPushMessageReceiverImpl extends OpenClientPushMessageReceiver {private static final String TAG = VIVOPushMessageReceiverImpl.class.getSimpleName();private static String sExt = "";@Overridepublic void onNotificationMessageClicked(Context context, UPSNotificationMessage upsNotificationMessage) {Log.i(TAG, "onNotificationMessageClicked upsNotificationMessage " + upsNotificationMessage.toString());Map<String, String> extra = upsNotificationMessage.getParams();sExt = extra.get("ext");}public static String getParams() {String tmp = sExt;sExt = "";return tmp;}@Overridepublic void onReceiveRegId(Context context, String regId) {Log.i(TAG, "onReceiveRegId = " + regId);}}
package xxx.xxx.xxx;import android.content.Context;import android.content.Intent;import com.meizu.cloud.pushsdk.MzPushMessageReceiver;import com.meizu.cloud.pushsdk.handler.MzPushMessage;import com.meizu.cloud.pushsdk.notification.PushNotificationBuilder;import com.meizu.cloud.pushsdk.platform.message.PushSwitchStatus;import com.meizu.cloud.pushsdk.platform.message.RegisterStatus;import com.meizu.cloud.pushsdk.platform.message.SubAliasStatus;import com.meizu.cloud.pushsdk.platform.message.SubTagsStatus;import com.meizu.cloud.pushsdk.platform.message.UnRegisterStatus;import android.util.Log;public class MEIZUPushReceiver extends MzPushMessageReceiver {private static final String TAG = MEIZUPushReceiver.class.getSimpleName();@Overridepublic void onMessage(Context context, String s) {Log.i(TAG, "onMessage method1 msg = " + s);}@Overridepublic void onMessage(Context context, String message, String platformExtra) {Log.i(TAG, "onMessage method2 msg = " + message + ", platformExtra = " + platformExtra);}@Overridepublic void onMessage(Context context, Intent intent) {String content = intent.getExtras().toString();Log.i(TAG, "flyme3 onMessage = " + content);}@Overridepublic void onUpdateNotificationBuilder(PushNotificationBuilder pushNotificationBuilder) {super.onUpdateNotificationBuilder(pushNotificationBuilder);}@Overridepublic void onNotificationClicked(Context context, MzPushMessage mzPushMessage) {Log.i(TAG, "onNotificationClicked mzPushMessage " + mzPushMessage.toString());}@Overridepublic void onNotificationArrived(Context context, MzPushMessage mzPushMessage) {super.onNotificationArrived(context, mzPushMessage);}@Overridepublic void onNotificationDeleted(Context context, MzPushMessage mzPushMessage) {super.onNotificationDeleted(context, mzPushMessage);}@Overridepublic void onNotifyMessageArrived(Context context, String s) {super.onNotifyMessageArrived(context, s);}@Overridepublic void onPushStatus(Context context, PushSwitchStatus pushSwitchStatus) {}@Overridepublic void onRegisterStatus(Context context, RegisterStatus registerStatus) {Log.i(TAG, "onRegisterStatus token = " + registerStatus.getPushId());// Call the API to report to the IM backend after obtaining the token}@Overridepublic void onUnRegisterStatus(Context context, UnRegisterStatus unRegisterStatus) {}@Overridepublic void onSubTagsStatus(Context context, SubTagsStatus subTagsStatus) {}@Overridepublic void onSubAliasStatus(Context context, SubAliasStatus subAliasStatus) {}@Overridepublic void onRegister(Context context, String s) {}@Overridepublic void onUnRegister(Context context, boolean b) {}}
package xxx.xxx.xxx;import com.google.firebase.messaging.FirebaseMessagingService;import android.util.Log;public class GoogleFCMMsgService extends FirebaseMessagingService {private static final String TAG = GoogleFCMMsgService.class.getSimpleName();@Overridepublic void onNewToken(String token) {super.onNewToken(token);Log.i(TAG, "onNewToken google fcm onNewToken : " + token);// Call the API to report to the IM backend after obtaining the token}}
public void init() {...if (BrandUtil.isBrandXiaoMi()) {// Mi offline pushMiPushClient.registerPush(this, PrivateConstants.XM_PUSH_APPID, PrivateConstants.XM_PUSH_APPKEY);} else if (BrandUtil.isBrandHonor()) {HonorMessaging.getInstance(context).turnOnPush().addOnCompleteListener(new OnCompleteListener<Void>() {@Overridepublic void onComplete(com.hihonor.push.sdk.tasks.Task<Void> task) {if (task.isSuccessful()) {TUIOfflinePushLog.i(TAG, "Honor turnOn push successfully.");} else {TUIOfflinePushLog.i(TAG, "Honor turnOn push failed." + task.getException());}}});new Thread(new Runnable() {@Overridepublic void run() {try {String pushToken = HonorInstanceId.getInstance(context).getPushToken();TUIOfflinePushLog.i(TAG, "Honor get pushToken " + pushToken);// Check if pushToken is nullif(!TextUtils.isEmpty(token)) {// Call the `setOfflinePushConfig` API of the IM SDK to report this tokenString pushToken = token;}} catch (com.hihonor.push.sdk.common.data.ApiException e) {TUIOfflinePushLog.i(TAG, "Honor get pushToken failed, " + e);}}}).start();}else if (BrandUtil.isBrandHuawei()) {// For Huawei offline push, set whether to receive the call example of the push notification bar messageHmsMessaging.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)) {// Call the `setOfflinePushConfig` API of the IM SDK to report this tokenString pushToken = token;}} catch (ApiException e) {DemoLog.e(TAG, "huawei get token failed, " + e);}}}.start();} else if (MzSystemUtils.isBrandMeizu(this)) {// Meizu offline pushPushManager.register(this, PrivateConstants.MZ_PUSH_APPID, PrivateConstants.MZ_PUSH_APPKEY);} else if (BrandUtil.isBrandVivo()) {// vivo offline pushPushClient.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);// Call the `setOfflinePushConfig` API of the IM SDK to report this tokenString pushToken = token;} else {// According to the vivo push documentation, state = 101 indicates that the vivo model or version does not support vivo push. Link: https://dev.vivo.com.cn/documentCenter/doc/156DemoLog.i(TAG, "vivopush open vivo push fail state = " + state);}}});} else if (HeytapPushManager.isSupportPush()) {// OPPO offline pushOPPOPushImpl oppo = new OPPOPushImpl();oppo.createNotificationChannel(this);// According to the OPPO documentation, the app must call the init(...) API before proceeding to subsequent operations.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);// Call the `setOfflinePushConfig` API of the IM SDK to report this tokenString pushToken = token;}});}}
public class HUAWEIHmsMessageService extends HmsMessageService {...@Overridepublic void onNewToken(String token) {DemoLog.i(TAG, "onNewToken token=" + token);// Call the `setOfflinePushConfig` API of the IM SDK to report this tokenString pushToken = token;}...}
V2TIMOfflinePushConfig v2TIMOfflinePushConfig = null;// Set `businessID` as the certificate ID of the vendor and report the token obtained after registration of the vendor push service.v2TIMOfflinePushConfig = new V2TIMOfflinePushConfig(businessID, token);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");}});
// When the app is switched to the backgroundV2TIMManager.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");}});// When the app is switched to the foregroundV2TIMManager.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());// For OPPO, you must set the `ChannelID` to receive push messages. The `ChannelID` must be identical with that in the console.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() {// Determine whether to log in to IM again based on the log-in status// 1. If the log-in status is V2TIMManager.V2TIM_STATUS_LOGOUT, you will redirect to the log-in interface, and log in to IM againif (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. Otherwise, it means the app is just in the background, directly parse the offline push parametersfinal 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);}}}
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidSound("Ringtone Name");v2TIMOfflinePushInfo.setIOSSound("Ringtone Name.mp3");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) {TUIChatUtils.callbackOnProgress(callBack, progress);}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidXiaoMiChannelID("Channel ID Applied by Manufacturer");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) {TUIChatUtils.callbackOnProgress(callBack, progress);}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidFCMChannelID(PrivateConstants.fcmPushChannelId);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) {TUIChatUtils.callbackOnProgress(callBack, progress);}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
Was this page helpful?