Configure Push Notifications

Last Updated on : 2023-05-22 06:38:24

Query status of push notifications

Returns the status of the push notifications feature. If this feature is disabled, device alerts, home messages, and notifications cannot be received.

API description

void getPushStatus(ITuyaResultCallback<PushStatusBean> callback);

Parameters

Parameter Description
callback The success or failure callback.

Example

 TuyaHomeSdk.getPushInstance().getPushStatus(new ITuyaResultCallback<PushStatusBean>() {
       @Override
       public void onSuccess(PushStatusBean result) {}
       @Override
       public void onError(String errorCode, String errorMessage) {}
 });

Enable or disable push notifications

Enables or disables the push notifications feature. If this feature is disabled, device alerts, home messages, and notifications cannot be received.

API description

void setPushStatus(boolean isOpen, ITuyaDataCallback<Boolean> callback);

Parameters

Parameter Description
isOpen Specifies whether to enable this feature.
callback The success or failure callback.

Example

TuyaHomeSdk.getPushInstance().setPushStatus(open, new ITuyaDataCallback<Boolean>() {
      @Override
      public void onSuccess(Boolean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Query push notification status by message type

API description

void getPushStatusByType(PushType type, ITuyaDataCallback<Boolean> callback);

Parameters

Parameter Description
type The type of message. Valid values:
  • 0: alert
  • 1: home message
  • 2: notification
  • 4: marketing message
callback The success or failure callback.

Example

TuyaHomeSdk.getPushInstance().getPushStatusByType(type, new ITuyaDataCallback<Boolean>() {
      @Override
      public void onSuccess(Boolean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Set push notification status by message type

API description

void setPushStatusByType(PushType type, isOpen, ITuyaDataCallback<Boolean> callback);

Parameters

Parameter Description
type The type of message. Valid values:
  • 0: alert
  • 1: home message
  • 2: notification
  • 4: marketing message
isOpen Specifies whether to enable this feature.
callback The success or failure callback.

Example

TuyaHomeSdk.getPushInstance().setPushStatusByType(pushType, checked, new ITuyaDataCallback<Boolean>() {
      @Override
      public void onSuccess(Boolean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Query a list of DND periods

API description

void getDNDList(ITuyaDataCallback<ArrayList<DeviceAlarmNotDisturbVO>> listener);

Parameters

Parameter Description
listener The success or failure callback.

Example

TuyaHomeSdk.getMessageInstance().getDNDList(new ITuyaDataCallback<DeviceAlarmNotDisturbVO>() {
      @Override
      public void onSuccess(DeviceAlarmNotDisturbVO result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Query DND settings for home devices

API description

void getDNDDeviceList(ITuyaDataCallback<ArrayList<NodisturbDevicesBean>> listener);

Parameters

Parameter Description
listener The success or failure callback.

Example

TuyaHomeSdk.getMessageInstance().getDNDDeviceList(new ITuyaDataCallback<NodisturbDevicesBean>() {
      @Override
      public void onSuccess(NodisturbDevicesBean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Query DND status for push notifications

API description

void getDeviceDNDSetting(ITuyaDataCallback<Boolean> listener);

Parameters

Parameter Description
listener The success callback. The current Do Not Disturb (DND) status is returned. Valid values:
  • true: DND is enabled.
  • false: DND is disabled.

Example

TuyaHomeSdk.getMessageInstance().getDeviceDNDSetting(new ITuyaDataCallback<Boolean>() {
      @Override
      public void onSuccess(Boolean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Enable or disable DND for push notifications

API description

void setDeviceDNDSetting(boolean open, ITuyaDataCallback<Boolean> listener);

Parameters

Parameter Description
open Specifies whether to enable this feature.
listener The success or failure callback.

Example

TuyaHomeSdk.getMessageInstance().setDeviceDNDSetting(open, new ITuyaDataCallback<Boolean>() {
      @Override
      public void onSuccess(Boolean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Add a DND period

API description

void addDNDWithStartTime(String startTime, String endTime, String devIds, String loops, ITuyaDataCallback<Long> listener);

Parameters

Parameter Description
startTime The start time of the DND period.
endTime The end time of the DND period.
devIds The list of device IDs.
loops The weekly schedule.
listener The success or failure callback.

Example

TuyaHomeSdk.getMessageInstance().addDNDWithStartTime(startTime, endTime, devIds, loops, new ITuyaDataCallback<Long>() {
      @Override
      public void onSuccess(Long result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Remove a DND period

API description

void removeDNDWithTimerId(long id, ITuyaDataCallback<Boolean> listener);

Parameters

Parameter Description
id The ID of the DND period to be removed.
listener The success or failure callback.

Example

TuyaHomeSdk.getMessageInstance().removeDNDWithTimerId(id, new ITuyaDataCallback<Boolean>() {
      @Override
      public void onSuccess(Boolean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});

Modify a DND period

API description

void modifyDNDWithTimerId(long nodisturbAlarmId, String mStartTime, String mEndTime, String devIds, String loops, ITuyaDataCallback<Boolean> listener);

Parameters

Parameter Description
nodisturbAlarmId The ID of the DND period to be modified.
mStartTime The start time of the DND period.
mEndTime The end time of the DND period.
loops The weekly schedule.
listener The success or failure callback.

Example

TuyaHomeSdk.getMessageInstance().modifyDNDWithTimerId(nodisturbAlarmId, mStartTime, mEndTime, devIds, loops, new ITuyaDataCallback<Boolean>() {
      @Override
      public void onSuccess(Boolean result) {}
      @Override
      public void onError(String errorCode, String errorMessage) {}
});