The following is the process of offline message push:
OPPO mobile phones use a highly customized Android system, with very strict management of the auto-start permissions of third-party apps. By default, third-party apps are not placed in the auto-start allowlist of the system. As apps running in the background are often killed by the system, we recommend that OPPO push be integrated on OPPO devices. OPPO push is a system-grade service for OPPO devices, with a high delivery rate. Currently, IM only supports the notification bar messages of OPPO push.
Note:
- This guide was prepared with direct reference to the official documentation of OPPO push. If OPPO push is changed, please refer to the OPPO push documentation on the official website.
- If you do not plan to implement an OPPO-specific offline push solution, skip this section.
AppId
, AppKey
, AppSecret
, and MasterSecret
.The official OPPO documentation states that ChannelIDs are required for push messages on OPPO Android 8.0 and above. Therefore, create a ChannelID for your app. Below is a sample code that creates a ChannelID called tuikit
:
public void createNotificationChannel(Context context) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "oppotest";
String description = "this is opptest";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("tuikit", name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
Note:
If you already have a certificate and only need to change its information, click Edit.
PushManager.getInstance().register(…)
, which is part of the OPPO PUSH SDK, to initialize the Opush service.onRegister
, which is a PushCallback
method, to obtain regId
.regId
.If you need to use OPPO push to push IM message notification, then after successful user login, you must use the setOfflinePushToken
method of TIMManager
to report the certificate ID generated and hosted by the IM console and regId returned by the OPPO push service to the IM server.
Note:
After the regId and certificate ID are correctly reported, the IM service can bind users with the corresponding device information. This enables the use of the OPPO push service to push notifications.
The following is a sample code defining Certificate ID as a constant:
/****** OPPO offline push parameter start ******/
// Certificate ID generated after uploading a third-party push certificate in the Tencent Cloud console
public static final long OPPO_PUSH_BUZID = 7005;
/****** OPPO offline push parameter start end ******/
The following is a sample code that reports Certificate ID and regId to the IM server:
/**
* Report Certificate ID and regId to IM in ThirdPushTokenMgr.java
*/
public class ThirdPushTokenMgr {
private static final String TAG = "ThirdPushTokenMgr";
private String mThirdPushToken;
public static ThirdPushTokenMgr getInstance () {
return ThirdPushTokenHolder.instance;
}
private static class ThirdPushTokenHolder {
private static final ThirdPushTokenMgr instance = new ThirdPushTokenMgr();
}
public void setThirdPushToken(String mThirdPushToken) {
this.mThirdPushToken = mThirdPushToken; // The regId value is passed here Describe it in accordance with the above-mentioned custom BroadcastReciever class documentation.
}
public void setPushTokenToTIM(){
String token = ThirdPushTokenMgr.getInstance().getThirdPushToken();
if(TextUtils.isEmpty(token)){
QLog.i(TAG, "setPushTokenToTIM third token is empty");
mIsTokenSet = false;
return;
}
TIMOfflinePushToken param = null;
if(IMFunc.isBrandXiaoMi()){ // Select different push services for different vendors.
param = new TIMOfflinePushToken(Constants.XM_PUSH_BUZID, token);
}else if(IMFunc.isBrandHuawei()){
param = new TIMOfflinePushToken(Constants.HW_PUSH_BUZID, token);
}else if(IMFunc.isBrandMeizu()){
param = new TIMOfflinePushToken(Constants.MZ_PUSH_BUZID, token);
}else if(IMFunc.isBrandOppo()){
param = new TIMOfflinePushToken(Constants.OPPO_PUSH_BUZID, token);
}else if(IMFunc.isBrandVivo()){
param = new TIMOfflinePushToken(Constants.VIVO_PUSH_BUZID, token);
}else{
return;
}
TIMManager.getInstance().setOfflinePushToken(param, new TIMCallBack() {
@Override
public void onError(int code, String desc) {
Log.d(TAG, "setOfflinePushToken err code = " + code);
}
@Override
public void onSuccess() {
Log.d(TAG, "setOfflinePushToken success");
mIsTokenSet = true;
}
});
}
}
After the Certificate ID and regId are successfully sent, the IM server will push the notification to the client through OPPO PUSH when the app is killed by the system before the user logs out.
Note:
- For a list of frequently asked questions, refer to OPPO PUSH FAQ.
- If the user logs out, or is logged out by IM (such as when the user logs in on another device), the device will no longer receive push messages.
You can select one of the following events: Open app, Open URL, or Open specific app interface.
This is the default event, which opens the app once the notification bar message is clicked.
You need to select Open URL in Step 2 and enter a URL that starts with either http
or https
, such as https://www.tencentcloud.com/document/product/269?from_cn_redirect=1
.
These are the ways you can open a specific app interface:
Activity (recommended)
This is rather simple. Enter the whole name of an Activity, such as com.tencent.qcloud.tim.demo.SplashActivity
Intent action
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
android.intent.action.VIEW
in the console.Set the custom content for the notification bar message before sending the message.
Note:
OPPO requires custom data to be in JSON format.
Android sample:
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("extKey", "ext content");
} catch (JSONException e) {
e.printStackTrace();
}
String extContent = jsonObject.toString();
TIMMessageOfflinePushSettings settings = new TIMMessageOfflinePushSettings();
settings.setExt(extContent.getBytes());
timMessage.setOfflinePushSettings(settings);
mConversation.sendMessage(false, timMessage, callback);
For information on configurations for the IM server, refer to the OfflinePushInfo Format Example.
On the console, after you set Open app or Open specific app interface as the click event for the push message and configure an Intent action or Activity, the client will be able to obtain the custom content from the corresponding Activity
once the notification bar message is clicked.
Bundle bundle = intent.getExtras();
Set<String> set = bundle.keySet();
if (set != null) {
for (String key : set) {
// key and value correspond to extKey and ext content set in Step 1.
String value = bundle.getString(key);
Log.i("oppo push custom data", "key = " + key + ":value = " + value);
}
}
OPPO does not support custom notification sounds.
Was this page helpful?