tencent cloud

Feedback

Last updated: 2024-06-13 10:21:45

    Step 1: Download and add the configuration file

    After completing the console manufacturer push information, download and add the configuration file to the project. Add the downloaded timpush-configs.json file to the assets directory of the application module:
    1. Choose to download the configuration file timpush-configs.json
    1. Add to the project
    
    
    
    
    
    

    Step 2: Integrate the TIMPush plugin

    // Integration of the push main package is mandatory
    implementation 'com.tencent.timpush:timpush:7.9.5668'
    // Integrate the corresponding manufacturer as needed
    implementation 'com.tencent.timpush:fcm:7.9.5668'
    implementation 'com.tencent.timpush:huawei:7.9.5668'
    implementation 'com.tencent.timpush:xiaomi:7.9.5668'
    implementation 'com.tencent.timpush:vivo:7.9.5668'
    implementation 'com.tencent.timpush:honor:7.9.5668'
    implementation 'com.tencent.timpush:meizu:7.9.5668'
    // Choose one of the two below
    // For the China region, choose to integrate this package
    implementation 'com.tencent.timpush:oppo:7.9.5668'
    // For other regions, choose to integrate this package
    implementation 'com.tencent.timpush:oppo-intl:7.9.5669'
    Note:
    1. TIMPush requires integration with IMSDK version 7.6.5011 or above.
    2. For users without UI or who haven't integrated other plugins, it is necessary to add integration with TUICore. It supports both source and Maven integration, as follows:
    def projects = this.rootProject.getAllprojects().stream().map { project -> project.name }.collect() api projects.contains("tuicore") ? project(':tuicore') : "com.tencent.liteav.tuikit:tuicore:7.9.5666"
    vivo and Honor configuration According to vivo and Honor manufacturer's access guidance, it is necessary to add the APPID and APPKEY to the manifest file, otherwise compilation issues will occur.
    Method 1
    Method 2
    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
    <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
    <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, HONOR, and Google FCM Adaptation
    Follow the vendor method to integrate the corresponding plugin and JSON configuration file.
    Note:
    The following adaptation for HONOR only requires configuration for version 7.7.5283 and above.
    1.1 Download the configuration file and place it under the root directory of the project:
    Huawei
    HONOR
    Google FCM
    Operation Path
    
    
    
    
    
    
    
    
    
    
    
    
    1.2 Add the following configuration under buildscript -> dependencies in your project-level build.gradle file:
    For Gradle version 7.1 and above
    Gradle version 7.0
    Versions Below Gradle 7.0
    Add the following configuration under buildscript -> dependencies in your project-level build.gradle file:
    buildscript {
    dependencies {
    ...
    classpath 'com.google.gms:google-services:4.3.15'
    classpath 'com.huawei.agconnect:agcp:1.4.1.300'
    classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
    }
    }
    In the project-level settings.gradle file, add the following repository configurations under pluginManagement -> repositories and dependencyResolutionManagement -> repositories:
    pluginManagement {
    repositories {
    gradlePluginPortal() mavenCentral() maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" } // Configure the Maven repository address for HMS Core SDK. maven {url 'https://developer.huawei.com/repo/'} maven {url 'https://developer.hihonor.com/repo'}
    }
    }
    dependencyResolutionManagement {
    ...
    repositories {
    mavenCentral() maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" } // Configure the Maven repository address for HMS Core SDK. maven {url 'https://developer.huawei.com/repo/'} maven {url 'https://developer.hihonor.com/repo'}
    }
    }
    }
    Add the following configuration under buildscript in your project-level build.gradle file:
    buildscript {
    repositories {
    mavenCentral() maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" } // Configure the Maven repository address for HMS Core SDK. maven {url 'https://developer.huawei.com/repo/'} maven {url 'https://developer.hihonor.com/repo'}
    }
    dependencies {
    ...
    classpath 'com.google.gms:google-services:4.3.15'
    classpath 'com.huawei.agconnect:agcp:1.4.1.300'
    classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
    }
    }
    Add the following repository configurations under dependencyResolutionManagement -> repositories in your project-level settings.gradle file:
    dependencyResolutionManagement {
    ...
    repositories {
    mavenCentral() maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" } // Configure the Maven repository address for HMS Core SDK. maven {url 'https://developer.huawei.com/repo/'} maven {url 'https://developer.hihonor.com/repo'}
    }
    }
    Add the following configuration under buildscript and allprojects in the project-level build.gradle file:
    buildscript {
    repositories {
    mavenCentral() maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" } // Configure the Maven repository address for HMS Core SDK. maven {url 'https://developer.huawei.com/repo/'} maven {url 'https://developer.hihonor.com/repo'}
    }
    dependencies {
    ...
    classpath 'com.google.gms:google-services:4.3.15'
    classpath 'com.huawei.agconnect:agcp:1.4.1.300'
    classpath 'com.hihonor.mcs:asplugin:2.0.1.300'
    }
    }
    
    allprojects {
    repositories {
    mavenCentral() maven { url "https://mirrors.tencent.com/nexus/repository/maven-public/" } // Configure the Maven repository address for HMS Core SDK. maven {url 'https://developer.huawei.com/repo/'} maven {url 'https://developer.hihonor.com/repo'}
    }
    }
    
    1.3 Add the following configuration in the app-level build.gradle file:
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'com.huawei.agconnect'
    apply plugin: 'com.hihonor.mcs.asplugin'
    After the above steps are performed, offline push notifications can be received.
    Note:
    If you want to integrate the TIMPush component as simply as possible, you need to log in and log out using the login/logout APIs provided by TUILogin of the TUICore component, and the TIMPush component automatically senses the log in and log out events. If you don't want to use the APIs provided by TUILogin, after completing the login/logout operation, you need to manually call the registerPush/unRegisterPush APIs of TIMPushManager.

    Step 3: Set obfuscation rules

    In the proguard-rules.pro file, add TIMPush-related classes to the non-obfuscation list:
    -keep class com.tencent.qcloud.** { *; }
    -keep class com.tencent.timpush.** { *; }

    Step 4: Message Delivery Statistics Configuration

    If you need to collect data reach statistics, please complete the configuration as follows:
    Huawei
    HONOR
    vivo
    Meizu
    
    
    
    Receipt Address:
    Singapore https://apisgp.im.qcloud.com/v3/offline_push_report/huawei
    South Korea https://apikr.im.qcloud.com/v3/offline_push_report/huawei
    USA https://apiusa.im.qcloud.com/v3/offline_push_report/huawei
    Germany https://apiger.im.qcloud.com/v3/offline_push_report/huawei
    Indonesia https://apiidn.im.qcloud.com/v3/offline_push_report/huawei
    Others in China https://api.im.qcloud.com/v3/offline_push_report/huawei
    Note:
    Huawei Push Certificate ID <= 11344, using Huawei Push v2 interface, does not support Reach and Click Receipt, please regenerate and update Certificate ID.
    
    
    
    Receipt Address:
    Singapore https://apisgp.im.qcloud.com/v3/offline_push_report/honor
    South Korea https://apikr.im.qcloud.com/v3/offline_push_report/honor
    USA https://apiusa.im.qcloud.com/v3/offline_push_report/honor
    Germany https://apiger.im.qcloud.com/v3/offline_push_report/honor
    Indonesia https://apiidn.im.qcloud.com/v3/offline_push_report/honor
    Others in China https://api.im.qcloud.com/v3/offline_push_report/honor
    Callback Address Configuration
    Configure Receipt ID in the IM Console
    
    
    
    Receipt Address:
    Singapore https://apisgp.im.qcloud.com/v3/offline_push_report/vivo South Korea https://apikr.im.qcloud.com/v3/offline_push_report/vivo USA https://apiusa.im.qcloud.com/v3/offline_push_report/vivo Germany https://apiger.im.qcloud.com/v3/offline_push_report/vivo Indonesia https://apiidn.im.qcloud.com/v3/offline_push_report/vivo Others in China https://api.im.qcloud.com/v3/offline_push_report/vivo
    
    
    
    Enable Receipt Switch
    Configure Receipt Address
    
    
    
    
    
    
    Receipt Address:
    Singapore https://apisgp.im.qcloud.com/v3/offline_push_report/meizu
    South Korea https://apikr.im.qcloud.com/v3/offline_push_report/meizu
    USA https://apiusa.im.qcloud.com/v3/offline_push_report/meizu
    Germany https://apiger.im.qcloud.com/v3/offline_push_report/meizu
    Indonesia https://apiidn.im.qcloud.com/v3/offline_push_report/meizu
    China https://api.im.qcloud.com/v3/offline_push_report/meizu
    Note:
    After turning on the receipt toggle, please make sure the receipt address is correctly configured. Not configuring it or configuring the wrong address will affect the push notification feature.
    Note:
    No configuration for message delivery statistics is required for other supported manufacturers.
    FCM currently does not support the push notification statistics feature.

    Step 5: Set the offline push parameters when sending a message

    When calling sendMessage to send a message, you can set offline push parameters through V2TIMOfflinePushInfo. By calling V2TIMOfflinePushInfo's setExt, you can set custom Definition ext data, which allows you to access the ext field in the callback of the click notification jump when the user starts the App after receiving an offline push. Then, based on the content of the ext field, navigate to the specified UI interface. See the sendMessage() method of ChatProvider for reference:
    V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
    v2TIMOfflinePushInfo.setTitle("Push Title");
    v2TIMOfflinePushInfo.setDesc("Push Content");
    
    OfflinePushExtInfo offlinePushExtInfo = new OfflinePushExtInfo(); offlinePushExtInfo.getBusinessInfo().setSenderId("senderID");
    offlinePushExtInfo.getBusinessInfo().setSenderNickName("senderNickName"); if (chatInfo.getType() == V2TIMConversation.V2TIM_GROUP) { offlinePushExtInfo.getBusinessInfo().setChatType(V2TIMConversation.V2TIM_GROUP); offlinePushExtInfo.getBusinessInfo().setSenderId("groupID"); } v2TIMOfflinePushInfo.setExt(new Gson().toJson(offlinePushExtInfo).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");
    v2TIMOfflinePushInfo.setAndroidHuaWeiCategory("IM");
    v2TIMOfflinePushInfo.setAndroidVIVOCategory("IM");
    
    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>() {
    @Override
    public void onProgress(int progress) {
    
    }
    
    @Override
    public void onError(int code, String desc) {
    TUIChatUtils.callbackOnError(callBack, TAG, code, desc);
    }
    
    @Override
    public void onSuccess(V2TIMMessage v2TIMMessage) {
    TUIChatLog.v(TAG, "sendMessage onSuccess:" + v2TIMMessage.getMsgID());
    message.setMsgTime(v2TIMMessage.getTimestamp());
    TUIChatUtils.callbackOnSuccess(callBack, message);
    }
    });

    Step 6: Parsing Offline Push Messages

    When a push is received, by clicking on the notification bar event, the component will notify the application in the form of a callback or broadcast. The application can then configure the App's redirect page in the callback. It is recommended to register the callback during the application's oncreate() function in the Application.
    The callback method is as follows:
    TUICore.registerEvent(TUIConstants.TIMPush.EVENT_NOTIFY, TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION, new ITUINotification() {
    @Override
    public void onNotifyEvent(String key, String subKey, Map<String, Object> param) {
    Log.d(TAG, "onNotifyEvent key = " + key + "subKey = " + subKey);
    if (TUIConstants.TIMPush.EVENT_NOTIFY.equals(key)) {
    if (TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION.equals(subKey)) {
    if (param != null) {
    String extString = (String)param.get(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY);
    // Getting ext for Definition redirect
    // Example: Redirect to the corresponding chat interface
    OfflinePushExtInfo offlinePushExtInfo = null;
    try {
    offlinePushExtInfo = new Gson().fromJson(extString, OfflinePushExtInfo.class);
    if (offlinePushExtInfo.getBusinessInfo().getChatAction() == OfflinePushExtInfo.REDIRECT_ACTION_CHAT) {
    String senderId = offlinePushExtInfo.getBusinessInfo().getSenderId();
    if (TextUtils.isEmpty(senderId)) {
    return;
    }
    TUIUtils.startChat(senderId, offlinePushExtInfo.getBusinessInfo().getSenderNickName(), offlinePushExtInfo.getBusinessInfo().getChatType());
    }
    } catch (Exception e) {
    Log.e(TAG, "getOfflinePushExtInfo e: " + e);
    }
    }
    }
    }
    }
    });
    The broadcast method is as follows:
    // Dynamic Broadcast Registration
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TUIConstants.TIMPush.NOTIFICATION_BROADCAST_ACTION);
    LocalBroadcastManager.getInstance(context).registerReceiver(localReceiver, intentFilter);
    
    // Broadcast Receiver
    public class OfflinePushLocalReceiver extends BroadcastReceiver {
    public static final String TAG = OfflinePushLocalReceiver.class.getSimpleName();
    
    @Override
    public void onReceive(Context context, Intent intent) {
    DemoLog.d(TAG, "BROADCAST_PUSH_RECEIVER intent = " + intent);
    if (intent != null) {
    String ext = intent.getStringExtra(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY);
    // Getting ext for Custom Redirect
    // Example: Redirect to the corresponding chat interface
    OfflinePushExtInfo offlinePushExtInfo = null;
    try {
    offlinePushExtInfo = new Gson().fromJson(extString, OfflinePushExtInfo.class);
    if (offlinePushExtInfo.getBusinessInfo().getChatAction() == OfflinePushExtInfo.REDIRECT_ACTION_CHAT) {
    String senderId = offlinePushExtInfo.getBusinessInfo().getSenderId();
    if (TextUtils.isEmpty(senderId)) {
    return;
    }
    TUIUtils.startChat(senderId, offlinePushExtInfo.getBusinessInfo().getSenderNickName(), offlinePushExtInfo.getBusinessInfo().getChatType());
    }
    } catch (Exception e) {
    Log.e(TAG, "getOfflinePushExtInfo e: " + e);
    }
    } else {
    Log.e(TAG, "onReceive ext is null");
    }
    }
    }
    Congratulations! You have completed the integration of the push plugin. Please be reminded: After the trial period or subscription expires, the push service (including regular message offline push, all-staff/Tag push, etc.) will automatically cease. To avoid affecting the normal use of your services, please make sure to purchase/renew in advance.
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support