TIMPushManager, TIMPushListener, TIMPushCallback, TIMPushMessage, and error codes.TIMPushManager is the push service manager class of the TIMPush Android SDK. Use it to register the push service, manage RegistrationID, configure the push channel and foreground notification display, and add push listeners.API | Description |
Gets the TIMPushManager singleton instance. | |
Registers the push service. | |
Unregisters and disables the offline push service. | |
Gets the unique push ID. | |
Sets a custom unique push ID. | |
Adds a push listener. | |
Removes a push listener. | |
Forces the device to use the FCM channel for offline push. | |
Disables notification bar pop-ups when the app is in the foreground. |
TIMPushListener is an abstract push listener class. Override the following methods as needed to receive push messages, push recall events, and notification click events.API | Description |
Called when a push message is received. | |
Called when a push message recall notification is received. | |
Callback when a notification bar message is clicked. |
onSuccess is triggered on success, and onError is triggered on failure.public abstract class TIMPushCallback<T> {public void onSuccess(T data) {}public void onError(int errCode, String errMsg, T data) {}}
Parameter | Type | Description |
data | T | Data returned in the success or failure callback. |
errCode | int | Error code in the failure callback. |
errMsg | String | Error description in the failure callback. |
TIMPushManager singleton instance.public static TIMPushManager getInstance();
TIMPushManager singleton. Call subsequent APIs through this instance.public abstract void registerPush(Context context, int sdkAppId, String appKey, TIMPushCallback callback);
Parameter | Type | Description |
context | Context | Android context object. |
sdkAppId | int | SDKAppID of the Push app. |
appKey | String | Client key of the Push app. |
callback | TIMPushCallback | Registration result callback. |
sdkAppId and appKey values to register the push service.appKey to null to enable offline push.public abstract void unRegisterPush(TIMPushCallback callback);
Parameter | Type | Description |
callback | TIMPushCallback | Unregistration result callback. |
public abstract void getRegistrationID(TIMPushCallback callback);
Parameter | Type | Description |
callback | TIMPushCallback | Result callback for the get operation. |
RegistrationID). You can then push messages to a specific device by RegistrationID.RegistrationID is the unique push ID of a device. It is generated automatically after a successful push registration by default, and can also be customized. You can push messages to a specific device by RegistrationID. Uninstalling and reinstalling the app changes this ID.public abstract void setRegistrationID(String registrationID, TIMPushCallback callback);
Parameter | Type | Description |
registrationID | String | Custom unique push ID. |
callback | TIMPushCallback | Result callback for the set operation. |
RegistrationID) for the device. Call this API before registering the push service.RegistrationID is the unique push ID of a device. It is generated automatically after a successful push registration by default, and can also be customized. You can push messages to a specific device by RegistrationID. Uninstalling and reinstalling the app changes this ID.public abstract void addPushListener(TIMPushListener listener);
Parameter | Type | Description |
listener | TIMPushListener | Push listener object. |
public abstract void removePushListener(TIMPushListener listener);
Parameter | Type | Description |
listener | TIMPushListener | Push listener object to remove. |
public abstract void forceUseFCMPushChannel(boolean enable);
Parameter | Type | Description |
enable | boolean | true: use the FCM channel; false: use the local (OEM) channel. |
public abstract void disablePostNotificationInForeground(boolean disable);
Parameter | Type | Description |
disable | boolean | true: disable; false: enable. |
TIMPushListener is an abstract push listener class. The base class provides empty implementations; override the following methods as needed.Callback | Trigger timing |
onRecvPushMessage | Triggered when the app is online and receives a Chat message that includes offlinePushInfo. |
onRevokePushMessage | Triggered when the app is online and receives a message recall notification. |
onNotificationClicked | Triggered when the user taps a notification bar message. This includes cases where the app is offline, the message is delivered via a manufacturer channel (Xiaomi / Huawei / OPPO / vivo / Honor / Meizu / FCM), and tapping the notification launches the app. |
offlinePushInfo. This callback is not triggered if the app process has already exited.public void onRecvPushMessage(TIMPushMessage message);
Parameter | Type | Description |
message | TIMPushMessage | Push message object. |
public void onRevokePushMessage(String messageID);
Parameter | Type | Description |
messageID | String | Unique message ID. |
public void onNotificationClicked(String ext);
Parameter | Type | Description |
ext | String | Offline message passthrough field. |
TIMPushMessage represents a push message object and implements the Serializable interface.public TIMPushMessage();
Property | Type | Description |
title | String | Offline push title. |
desc | String | Offline push content. |
ext | String | Offline push passthrough content. |
messageID | String | Unique message ID. |
Method | Return type | Description |
setTitle(String title) | void | Sets the offline push title. |
getTitle() | String | Gets the offline push title. |
setDesc(String description) | void | Sets the offline push content. |
getDesc() | String | Gets the offline push content. |
setExt(String ext) | void | Sets the offline push passthrough content. |
getExt() | String | Gets the offline push passthrough content. |
setMessageID(String messageID) | void | Sets the unique message ID. |
getMessageID() | String | Gets the unique message ID. |
toString() | String | Returns the string representation of the message object. |
TIMPushConstants defines the business error codes of the TIMPush SDK.Error code | Value | Description |
ERR_INVALID_PARAM | 800000 | Invalid parameter. |
ERR_NOT_LOGINED | 800001 | Chat account not logged in before registering push. |
ERR_INVALID_SDK_APPID | 800002 | Invalid sdkAppID parameter for push registration. |
ERR_REGISTER_PUSH_INIT_FAILED | 800003 | Failed to initialize the SDK. |
ERR_REGISTER_PUSH_CONNECT_FAILED | 800004 | Failed to establish the long connection. |
ERR_REGISTER_PUSH_FAILED_BUILT_IN_DEVICE | 800005 | Failed to register push on the local (OEM) channel. |
ERR_REGISTER_PUSH_FAILED_TRY_FCM | 800006 | After local (OEM) channel registration failed, FCM channel registration also failed. |
ERR_REGISTER_PUSH_FAILED_DETECT_CHANNELS | 800007 | Failed to detect all channels. |
ERR_REGISTER_PUSH_FAILED_TIMEOUT | 800008 | Push service registration timed out. |
ERR_REGISTER_TOKEN_EMPTY | 800009 | Push registration token is empty. |
ERR_SET_PUSH_TOKEN_FAILED | 800010 | Failed to set the token on the SDK. |
ERR_DISABLE_AUTO_REGISTER_PUSH_FAILED | 800011 | Failed to disable auto registration. |
ERR_DISABLE_REQUEST_POST_NOTIFICATION_PERMISSION_FAILED | 800012 | Failed to disable the push permission request. |
ERR_CREATE_NOTIFICATION_CHANNEL_FAILED | 800013 | Failed to create the notification channel. |
ERR_SET_PUSH_CONFIG_FAILED | 800014 | Failed to set the push configuration. |
ERR_CALL_EXPERIMENTAL_API_FAILED | 800015 | Experimental API call failed. |
ERR_SET_APP_LANGUAGE_FAILED | 800016 | Failed to configure the device language. |
ERR_HTTPS_REQUEST_FAILED | 800017 | HTTPS request failed. |
フィードバック