Menu

Android

Last updated: 2023-09-21 15:37:01Download PDF
The offline call push feature enables your application to receive audio/video calls even if it runs in the background or is offline. TUICallKit integrates the TUIOfflinePush component to implement the offline call push feature. This document describes how to integrate the TUIOfflinePush component in your audio/video call project.

Preparations

1. Register your application on vendors' push platforms. The offline push feature relies on the vendors' own channels. You need to register your application on the vendors' push platforms to get parameters such as APPID and APPKEY.
Note
The following two files will be used in subsequent steps:
When registering on Huawei Push, download and save the agconnect-services.json file.
When registering on Google FCM, download and save the google-services.json file.

Google FCM:

img


2. Configure in the Chat console
You need to enter the same package name when registering on each vendor channel for message interconnection. Record the generated ID, APPID, and APPKEY, which will be used in subsequent steps.


Step 1. Download and import the component

1. Go to GitHub, clone or download the code, and copy the tuiofflinepush subdirectory in the Android directory to the same directory as app in your project, as shown below.

img


2. Find the settings.gradle file in the project root directory and add the following code:
include ':tuiofflinepush'
3. Find the build.gradle file in the app directory and add the following code to declare the dependencies of the current application on the TUIOfflinePush component just added:
api project(':tuiofflinepush')

Step 2. Configure the project

1. In the app directory, find the build.gradle file and rename the application package as needed.
applicationId 'com.****.trtc'
2. In the app directory, find the build.gradle file and set ViVo access parameters VIVO_APPKEY, VIVO_APPID, and HONOR_APPID to avoid compilation or execution errors.
manifestPlaceholders = [
"VIVO_APPKEY": "PLACEHOLDER",
"VIVO_APPID" : "PLACEHOLDER",
"HONOR_APPID": "PLACEHOLDER"
]
3. Configure the files for Huawei and Google push platforms: In the app directory, replace the google-services.json file, which is the one saved when you registered on Google FCM during Preparations. In the app directory, add the agconnect-services.json file, which is the one saved when you registered on Huawei Push during Preparations.
4. Enter the ID, APPID, APPKEY recorded during Preparations in the PrivateConstants file and check whether the parameter configuration is correct. Enter the following parameters:
public class PrivateConstants {
/****** Mi offline push parameters start ******/
// Certificate ID generated after uploading a third-party push certificate in the Tencent Cloud console
public static final long XM_PUSH_BUZID = ID of the certificate assigned to your application
// `APPID` and `APPKEY` assigned by the Mi open platform
public 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 ******/
}
Caution
This step is very important. Carefully check whether the parameter configuration is correct.
After you complete the above steps, your project can use the offline call push feature of TUICallKit.

Step 3. Customize the offline notification content

TUICallKit provides the default notification format. However, if you want to customize the notification content, modify the OfflinePushInfoConfig.java file.
public static TUIOfflinePushInfo createOfflinePushInfo(Context context) {
TUICallDefine.OfflinePushInfo pushInfo = new TUICallDefine.OfflinePushInfo();
pushInfo.setTitle("mike");
pushInfo.setDesc("You have receive a new call");
//OPPO must set a ChannelID to receive push messages. This channelID needs to be the same as the console.
pushInfo.setAndroidOPPOChannelID("tuikit");
pushInfo.setIgnoreIOSBadge(false);
pushInfo.setIOSSound("phone_ringing.mp3");
pushInfo.setAndroidSound("phone_ringing"); //Note:don't add suffix
//VIVO message type: 0-push message, 1-System message(have a higher delivery rate)
pushInfo.setAndroidVIVOClassification(1);
//FCM channel ID, you need change PrivateConstants.java and set "fcmPushChannelId"
pushInfo.setAndroidFCMChannelID("fcm_push_channel");
//Huawei message type
pushInfo.setAndroidHuaWeiCategory("IM");
//IOS push type: if you want user VoIP, please modify type to TUICallDefine.IOSOfflinePushType.VoIP
pushInfo.setIOSPushType(TUICallDefine.IOSOfflinePushType.APNs);
return pushInfo;
}

Step 4. Customize the offline notification sound

Offline notification sound only supports customization for Huawei, Xiaomi, FCM and APNs. Other manufacturers such as OPPO, VIVO, Honor, etc. are not supported at the moment.
TUICallKit introduces the TUIOfflinePushPush component, which needs to call the following method at the start of the application to enable the ability to customize the ringtone for offline notifications.
public class DemoApplication extends Application {
    @Override
public void onCreate() {
        TUIOfflinePushConfig.getInstance().setAndroidPrivateRing(true);
    }
}

1. Huawei And APNs

Invoke the interfaces setAndroidSound()and setIOSSound().
Customize the ringtone resource file and add it to the res/raw directory of the local Android Studio project. Refer to Step 3 to set ringtones.
TUICallDefine.OfflinePushInfo pushInfo = new TUICallDefine.OfflinePushInfo();
pushInfo.setIOSSound("phone_ringing.mp3");
pushInfo.setAndroidSound("phone_ringing");
Note:
IMSDK 6.1.2155 and above versions are supported.

2. Xiaomi

(1) Before Android 8.0, invoke the interfaces setAndroidSound()and setIOSSound(). Customize the ringtone resource file and add it to the res/raw directory of the local Android Studio project(Refer to Huawei).
(2) After Android 8.0, you also need to log in to the Xiaomi vendor console and create a channel with proper configuration, and the ringtone file needs to be added to the local Android Studio project res/raw directory.
TUICallDefine.OfflinePushInfo pushInfo = new TUICallDefine.OfflinePushInfo();
pushInfo.setIOSSound("phone_ringing.mp3");
pushInfo.setAndroidSound("phone_ringing");
pushInfo.setAndroidXiaoMiChannelID("channelID");
Note:
The method Before Android 8.0, IMSDK 6.1.2155 and above versions are supported.
The method After Android 8.0, IMSDK 7.0.3754 and above versions are supported.

3. FCM

(1) Before Android 8.0, invoke the interfaces setAndroidSound()and setIOSSound(). Customize the ringtone resource file and add it to the res/raw directory of the local Android Studio project(Refer to Huawei).
(2) After Android 8.0, FCM needs to configure channelID and ringtone resources. TUIOfflinePush component has handled the playback of custom ringtones. The ringtone file needs to be added to the res/raw directory of your local Android Studio project and specify the name of the ringtone and the name of the channel ID, as shown in PrivateConstants.
public class PrivateConstants {
// FCM: channel ID
    public static String fcmPushChannelId = "FCM ChannelID";
    // FCM: ringtone and don't add suffix
    public static String fcmPushChannelSoundName = "FCM ringtone";
}
Note:
The method Before Android 8.0, IMSDK 6.1.2155 and above versions are supported.
The method After Android 8.0, IMSDK 7.0.3754 and above versions are supported.
FCM only supports custom ringtones or setting channel ID in certificate mode.

FAQs

If users cannot receive offline push notifications, contact us for troubleshooting.

1. What should I do if notifications cannot be received?

Test the push service in the vendor console. If notifications can be pushed successfully, the vendor channel is normal. Then, check whether vendor parameters are configured correctly in the TUIOfflinePush console, and if not, enter the parameters as required. (As tested, you must configure the message type in the console for vivo X9).
Some phones will send notifications to the Unimportant Notifications folder. In this case, drag down the status bar and check whether the notifications are in the Unimportant Notifications folder.
Filter the following log to check whether TUIOfflinePush is registered successfully:
TUIOfflinePush

2. Why can't the locked screen turn on when a notification is received?

Due to restrictions imposed by the vendor and platform, Android phones require different permissions when their screen is locked. Troubleshoot as follows:
Check whether the system lock screen notification permission is enabled. Some vendors have imposed unified restrictions. For example, if a Mi phone doesn't turn on its screen when receiving offline notifications, select Settings > Lock screen and toggle on Wake Lock screen for notifications.
Check whether the lock screen notification permission of the application is enabled. For example, on a Mi phone, you need to toggle on Allow Lock screen notifications.
Note
If you need compatibility processing for this problem, contact us for assistance.

3. Why can't the call UI be pulled when I click an offline push notification?

Filter the following log to check whether the call request is detected:
onReceiveNewInvitation

4. Why can't the call UI be pulled to the foreground when the application is running in the background?

To automatically pull the application from the background to the foreground, it is necessary to check whether the "background autostart" or "floating window" permission is enabled on the application.
Note that different vendors or even different Android versions from the same vendor offers different permissions and permission names. For example, you only need to enable the background pop-up window permission for Mi 6, while you need to enable both the background pop-up window and floating window display permissions.
Note
If you have manually granted all the necessary permissions and still cannot move your application to the foreground, it may be a vendor compatibility issue.

5. Badge

Currently, only Huawei supports generating badges when receiving offline messages, and other manufacturers do not support it for now. For Huawei, please refer to its official documentation "Interface Description for Badging on Huawei Desktop.
In the introduced TUIOfflinePush component, this method is also called for setting badges:
public void updateBadge(final Context context, final int number) {
if (BrandUtil.getInstanceType() != TUIOfflinePushConfig.BRAND_HUAWEI) {
return;
}
try {
Bundle extra = new Bundle();
extra.putString("package", context.getPackageName());
extra.putString("class", PrivateConstants.huaweiBadgeClassName); //huaweiBadgeClassName is your app main activity
extra.putInt("badgenumber", number);
context.getContentResolver().call(Uri.parse("content://com.huawei.android.launcher.settings/badge/"), "change_badge", null, extra);
} catch (Exception e) {
}
}
If you want to clear the badge, you can call this method at the appropriate time to set the badge to 0.