Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HUAWEI HMS Core
Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.
| CLASS info |
| public class HmsMessageService extends Service |
Basic class for receiving downlink messages or updated tokens in HUAWEI Push Kit. To receive messages pushed by the Push Kit server or updated tokens, you need to declare the implementation class of HmsMessageService in the AndroidManifest.xml file of the app. In the implementation class, you need to override all methods in the base class to process the data returned by the HMS Core Push SDK. You ensure that all callbacks in HmsMessageService must complete processing within 10 seconds. If the processing time exceeds 10 seconds, you need to create a job for processing. The AndroidManifest.xml file must contain the following information: Collapse Word wrap Dark theme Copy code |
| Return type | Method name |
| void | onMessageReceived(RemoteMessage message) Receives data messages. |
| void | onMessageSent(String msgId) Called after an uplink message is successfully sent. |
| void | onSendError(String msgId, Exception exception) Called after an uplink message fails to be sent. |
| void | onNewToken(String token) Called after the Push Kit server updates the token. |
| void | onTokenError(Exception exception) Called when a token fails to be applied for. |
| void | onMessageDelivered(String msgId, Exception exception) Sends the response from the app server to the app after an uplink message reaches the app server if the receipt is enabled. |
| Method |
| public void onMessageReceived(RemoteMessage message) |
Receives data messages pushed by the app server. |
Parameters
| Parameter name | Parameter desc |
| message | Data message. |
| Method |
| public void onMessageSent(String msgId) |
| Called after an uplink message is successfully sent. After the app calls the send(RemoteMessage message) method in HmsMessaging to send an uplink message, the app class extends the HmsMessageService class and overrides the onMessageSent(String msgId) method to receive the sending result. If the onMessageSent(String msgId) method is called, the message is sent successfully. |
Parameters
| Parameter name | Parameter desc |
msgId | Message ID. |
| Method |
| public void onSendError(String msgId, Exception exception) |
Called after an uplink message fails to be sent. After the app calls the send(RemoteMessage message) method in HmsMessaging to send an uplink message, the app class extends the HmsMessageService class and overrides the onSendError(String msgId, Exception exception) method to receive the sending result. |
Parameters
| Parameter name | Parameter desc |
msgId | Message ID. |
exception | Error code obtained by getErrorCode() in BaseException and the description obtained by getMessage(). |
| Method |
| public void onNewToken(String token) |
| When an app calls the getToken method to apply for a token from the server, if the server does not return the token during current method calling, the server can return the token through this method later. The main scenarios are as follows: 1. If the getToken method fails to be called, HUAWEI Push Kit automatically calls the method again, and the requested token is returned through the onNewToken method. 2. If the server determines that the requested token has expired, the updated token will be returned through the onNewToken method. 3. If the EMUI version of a Huawei device is earlier than 10.0, the token is returned through the onNewToken method. |
Parameters
| Parameter name | Parameter desc |
| token | Token applied for by an app from the HUAWEI Push Kit server through the getToken method. |
| Method |
| public void onTokenError(Exception exception) |
| Callback method used when a token fails to be applied for. |
Parameters
| Parameter name | Parameter desc |
| exception | Exception information returned when a token fails to be applied for. |
| Method |
| public void onMessageDelivered(String msgId, Exception exception) |
Sends the response from the app server to the app after an uplink message reaches the app server if the receipt is enabled. |
Parameters
| Parameter name | Parameter desc |
msgId | ID of a sent message. |
| exception | Exception information contained in a receipt. |
Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.