Notifications of Devices Getting Offline

Last Updated on : 2024-03-04 08:45:15download

A device might get offline unexpectedly or do not respond over the network after the device is paired. In this case, you can enable offline notifications for the device. If the device goes offline, it will send a notification to a specified user. To enable this feature, you can subscribe to push notifications.

Check support for offline notifications

API description

void getOfflineReminderSupportStatus(String hdId,ITuyaResultCallback<IsSupportOffLineBean> callback);

Parameters

Parameter Description
hdId The device ID.
callback The callback.

Example

mDevice.getOfflineReminderSupportStatus(hdId, new ITuyaResultCallback<IsSupportOffLineBean>() {
            @Override
            public void onSuccess(IsSupportOffLineBean result) {
                if(result.isOfflineReminder()){
                    Toast.makeText(mContext, "Offline notifications supported", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                Toast.makeText(mContext, "Failure callback", Toast.LENGTH_SHORT).show();
            }
        });

Query offline notification status

API description

void getOfflineReminderStatus(String devId, ITuyaResultCallback<Boolean> callback);

Parameters

Parameter Description
devId The device ID.
callback The callback.

Example

mDevice.getOfflineReminderStatus(devId, new ITuyaResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
                if(result){
                    Toast.makeText(mContext, "Offline notifications enabled", Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(mContext, "Offline notifications disabled", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(String errorCode, String errorMessage) {
                Toast.makeText(mContext, "Failure callback", Toast.LENGTH_SHORT).show();
            }
        });

Set offline notifications

API description

void setOfflineReminderStatus(String devId, boolean isWarn, IResultCallback callback);

Parameters

Parameter Description
devId The device ID.
isWarn Specifies whether to enable offline notifications.
callback The callback.

Example

mDevice.setOfflineReminderStatus(devId, true, new IResultCallback() {
            @Override
            public void onError(String code, String error) {
                Toast.makeText(mContext, "Failed to enable offline notifications", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onSuccess() {
                Toast.makeText(mContext, "Offline notifications enabled", Toast.LENGTH_SHORT).show();
            }
        });