Integrate with Umeng

Last Updated on : 2024-01-10 09:09:16

Tuya supports push notifications through third-party channels, such as Google Firebase Cloud Messaging (FCM), Umeng, Xiaomi, Huawei, and MEIZU. To integrate this feature into your app development, you must request app key information from each third-party platform and initialize the SDK as instructed in the documents. This topic describes how to integrate with U-Push to enable push notifications through Umeng.

Configure key information

  1. If your push notifications are targeted to mainland China and developed based on U-Push, follow Umeng’s documents to integrate U-Push into your project.

  2. Request key information required by push notifications through Umeng. For more information, see Apply for Push Key from Umeng.

  3. Log in to the Tuya IoT Development Platform and go to the SDK Development page. On the Certificates tab, copy and paste the requested key information to the Push (Umeng) section.

    Integrate with Umeng

    The configurations must meet the following requirements:

    • The package name on U-Push is the same as the SDK app package name on the Tuya IoT Development Platform.
    • The values of Message Secret and Master Secret must be correct and cannot be exchanged.
    • The checkbox to enable the server IP address on U-Push can only be disabled manually.

Integrate with U-Push

Step 1: Set a user’s alias

After your project is integrated with Umeng, use the Umeng SDK to set the user ID. Push notifications are sent to users by user IDs.

mPushAgent.setAlias(aliasId, ALIAS_TYPE, new UTrack.ICallBack() {
    @Override
    public void onMessage(boolean isSuccess, String message) {
    }
});

Parameters

Parameter Description
aliasId It can be the unique ID that is automatically assigned by your app to each user.
ALIAS_TYPE Set it to TUYA_SMART.

Step 2: Register alias to cloud

Register aliasId to the Tuya IoT Cloud.

Parameters

Parameter Description
aliasId The user alias. After the user alias obtained in the previous step is registered to the cloud, Tuya Smart Life App SDK will send push notifications to the user’s app.
pushProvider The type of push notification. Set the value to umeng.

Example

TuyaHomeSdk.getPushInstance().registerDevice(String aliasId, String pushProvider, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
    }

    @Override
    public void onSuccess() {

    }
});

Step 3: Configure third-party channel

If a third-party channel is used, the activity of the dialog box must be named SpecialPushActivity. For example, to enable push notifications through Umeng, SpecialPushActivity inherits from UmengNotifyClickActivity, and the complete package name path is com.activity.SpecialPushActivity.

Receive push notifications

For more information on how to integrate with custom push notifications through Umeng, see Umeng’s documents. Example:

UmengMessageHandler messageHandler = new UmengMessageHandler(){
    @Override
    public void dealWithCustomMessage(final Context context, final UMessage msg) {
        new Handler(getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(context, msg.custom, Toast.LENGTH_LONG).show();
            }
        });
    }
};

mPushAgent.setMessageHandler(messageHandler);
  • The content in msg.custom is the received push notification. The content of msg.custom is delivered over the protocol in the following format:
    custom=tuya://message?a=view&ct="title"&cc="content"&p=>{}&link=tuyaSmart%3A%2F%2Fbrowser%3Furl%3Dhttp%253A%252F%252Fwww.baidu.com;
    
  • The content is parsed into key information, such as the title, body, and navigation information, using Uri uri = Uri.parse(message);.

Unbind a user

API description

You can call the following Umeng method to remove a registration token. This applies when you want to unbind your app from users in specific scenarios, such as logout.

mPushAgent.deleteAlias(aliasId, "TUYA_SMART", new UTrack.ICallBack() {
    @Override
    public void onMessage(boolean isSuccess, String message) {
    }
});

Parameters

Parameter Description
aliasId The unique ID that is automatically assigned by your app to each user.
ALIAS_TYPE Set it to TUYA_SMART.

Send push notifications

After you integrate with the capabilities of push notifications, you can configure push notifications on the Tuya IoT Development Platform.

Create an operation push notification

Log in to the Tuya IoT Development Platform and go to the Marketing push page. Then, users can receive your in-app message regarding new arrivals, trending information, and more. This can help to build user engagement.

Integrate with Umeng

Create a device push notification

To create a device push notification, log in to the Tuya IoT Development Platform, and in the left-side navigation pane, choose Product > Notifications. For more information, see Configure Push Notification.

Integrate with Umeng