Last Updated on : 2024-06-26 09:45:56download
This topic describes how to integrate Google’s Firebase Cloud Messaging (FCM) into your Android project. The instructions in this topic apply to your services deployed outside mainland China.
Project configuration: For more information, see Add Firebase to your Android project.
Client configuration: For more information, see Set up a Firebase Cloud Messaging client app on Android.
To use FCM, users’ mobile phones must be installed with Google services and support access to Google.
Configure Sender ID and Server Key and upload the google-services.json
file in the Push (Google FCM) section at Tuya Developer Platform > App > App SDK > Optional Setting > Certificates. For more information, see Register FCM.
We recommend that you copy and paste the required content to the Sender ID and Server Key fields to ensure correct settings.
Call the onTokenRefresh
method that inherits the class FirebaseInstanceIdService
to listen for the generated token and register it to the cloud.
ThingHomeSdk.getPushInstance().registerDevice(String token, String pushProvider, new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
}
});
Parameters
Parameter | Description |
---|---|
token | The token generated by FCM. |
pushProvider | The type of push notification. Set the value to fcm . |
Call the onMessageReceived
method that inherits the class FirebaseMessagingService
to receive and process push notifications. These messages are included in message.getData()
.
public class MyFcmListenerService extends FirebaseMessagingService {
public static final String TAG = "MyFcmListenerService";
public static HashMap<String, Long> pushTimeMap = new HashMap<>();
@Override
public void onMessageReceived(RemoteMessage message) {
Log.d(TAG, "FCM message received" + message.getData().toString());
}
}
You can call the following FCM method to remove a registration token. This applies when you want to unbind your app from users in specific scenarios, such as logout.
FirebaseInstanceId.getInstance().deleteInstanceId();
The API methods mentioned in this topic are based on SDK v20.1.6 and they are not recommended for use. To integrate with a later version, follow the instructions in FirebaseInstanceId.
After you integrate with the capabilities of push notifications, you can configure push notifications on the Tuya Developer Platform.
Go to Tuya Developer Platform > Marketing push and create a marketing push notification. This allows users to receive your in-app messages regarding new arrivals, trending information, and more, and improves user engagement.
To create a device push notification, go to Tuya Developer Platform > Product > Notifications. For more information, see Configure Push Notification.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback