Message Push

Last Updated on : 2025-01-22 07:48:06download

This topic describes how to manage push notifications.

On/off status

Get on/off status of push notifications

fun getPushSwitchStatusByType(type: Int, listener: Business.ResultListener<Boolean>?)

Parameter description

Parameter Type Description
msgType Int The type of push notifications.
listener Business.ResultListener<Boolean> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().getPushSwitchStatusByType(
    MessageContants.LINE_PUSH_TYPE,
    object : Business.ResultListener<Boolean> {
        override fun onSuccess(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultSuccess(WHAT_GET_SWITCH_STATUS_SUCCESS, p1)
        }

        override fun onFailure(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultError(
                WHAT_GET_SWITCH_STATUS_FAILURE,
                p0?.getErrorCode(),
                p0?.getErrorMsg()
            )
        }
})

Set on/off status of push notifications

fun setPushSwitchStatusByType(
        type: Int,
        isClose: Boolean,
        listener: Business.ResultListener<Boolean>?
    )

Parameter description

Parameter Type Description
type Int The message type.
isClose Boolean The enabling status.
listener Business.ResultListener<Boolean> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().setPushSwitchStatusByType(
    MessageContants.LINE_PUSH_TYPE,
    true,
    object : Business.ResultListener<Boolean> {
        override fun onSuccess(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultSuccess(WHAT_SET_SWITCH_STATUS_SUCCESS, p1)
        }

        override fun onFailure(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultError(
                WHAT_SET_SWITCH_STATUS_FAILURE,
                p0?.getErrorCode(),
                p0?.getErrorMsg()
            )
        }
    })

Get the on/off status of the device alert push channel

fun getPushSwitchStatusByType(type: Int, listener: Business.ResultListener<Boolean>?)

Parameter description

Parameter Type Description
type Int The type of push notifications.
listener Business.ResultListener<Boolean> The result returned from the handler function.

Example

    mPersonalMessageCore.getPushSwitchStatusByType(
    MessageContants.LINE_PUSH_TYPE,
    object : Business.ResultListener<Boolean> {
        override fun onSuccess(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultSuccess(WHAT_GET_SWITCH_STATUS_SUCCESS, p1)
        }

        override fun onFailure(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultError(
                WHAT_GET_SWITCH_STATUS_FAILURE,
                p0?.getErrorCode(),
                p0?.getErrorMsg()
            )
        }
    })

Set the on/off status of the device alert push channel

    fun setPushSwitchStatusByType(
        type: Int,
        isClose: Boolean,
        listener: Business.ResultListener<Boolean>?
    )

Parameter description

Parameter Type Description
type Int The message type.
isClose Boolean The enabling status.
listener Business.ResultListener<Boolean> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().setPushSwitchStatusByType(
    MessageContants.LINE_PUSH_TYPE,
    true,
    object : Business.ResultListener<Boolean> {
        override fun onSuccess(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultSuccess(WHAT_SET_SWITCH_STATUS_SUCCESS, p1)
        }

        override fun onFailure(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
            resultError(
                WHAT_SET_SWITCH_STATUS_FAILURE,
                p0?.getErrorCode(),
                p0?.getErrorMsg()
            )
        }
    })

Alerts

Get the interval time for non-recurring alerts

fun getNonRepeatRemindMinute(
    pushType: PushType,
    callback: IThingDataCallback<AlarmRemindBean>?
)

Parameter description

Parameter Type Description
pushType PushType The alert type.
callback IThingDataCallback<Boolean> The result callback.

Example

PersonalMessageCore.newThingSmartMessagePushCore().setNonRepeatRemindByType(
    pushType,
    noRepeatRemindDuration,
    object : IThingDataCallback<Boolean> {
        override fun onSuccess(result: Boolean?) {
            continuation.resume(result)
        }

        override fun onError(errorCode: String?, errorMessage: String?) {
            continuation.resumeWithException(
                ErrorException(
                    errorCode,
                    errorMessage
                )
            )
        }
    })

Set the interval time for non-recurring alerts

fun setNonRepeatRemindByType(
    pushType: PushType,
    noRepeatRemindDuration: Int,
    callback: IThingDataCallback<Boolean>?
)

Parameter description

Parameter Type Description
pushType PushType The alert type.
noRepeatRemindDuration Int The time setting.
callback IThingDataCallback<Boolean> The result callback.

Example

PersonalMessageCore.newThingSmartMessagePushCore().setNonRepeatRemindByType(
            pushType,
            noRepeatRemindDuration,
            object : IThingDataCallback<Boolean> {
                override fun onSuccess(result: Boolean?) {
                    continuation.resume(result)
                }

                override fun onError(errorCode: String?, errorMessage: String?) {
                    continuation.resumeWithException(
                        ErrorException(
                            errorCode,
                            errorMessage
                        )
                    )
                }
            })

Get the alert service information of a single device

fun getWarnDeviceConfig(
        gid: String,
        serverType: String,
        deviceId: String,
        listener: Business.ResultListener<ArrayList<WarnDeviceConfig>>?
    )

Parameter description

Parameter Type Description
gid String The identifier of the specified device configuration group.
serverType String The service type.
deviceId String The device ID.
listener Business.ResultListener<ArrayList<WarnDeviceConfig>> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().getWarnDeviceConfig("group123", "production_server", "device001",
    object : Business.ResultListener<ArrayList<WarnDeviceConfig>> {
        override fun onFailure(
            bizResponse: BusinessResponse?,
            bizResult: ArrayList<WarnDeviceConfig>?,
            apiName: String?
        ) {
            continuation.resumeWithException(
                ErrorException(
                    bizResponse?.errorCode,
                    bizResponse?.errorMsg
                )
            )
        }

        override fun onSuccess(
            bizResponse: BusinessResponse?,
            bizResult: ArrayList<WarnDeviceConfig>?,
            apiName: String?
        ) {
            continuation.resume(bizResult)
        }
    })

Set the alert service information of a single device

fun updateWarnDeviceConfig(
        noticeRuleList: WarnNoticeExpr,
        listener: Business.ResultListener<Boolean>
    )

Parameter description

Parameter Type Description
noticeRuleList WarnNoticeExpr A list of warning and notification rules.
listener Business.ResultListener<Boolean> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().updateWarnDeviceConfig(warnNoticeExpr,
    object : Business.ResultListener<Boolean> {
        override fun onFailure(
            bizResponse: BusinessResponse?,
            bizResult: Boolean?,
            apiName: String?
        ) {
            continuation.resumeWithException(
                ErrorException(
                    bizResponse?.errorCode,
                    bizResponse?.errorMsg
                )
            )
        }

        override fun onSuccess(
            bizResponse: BusinessResponse?,
            bizResult: Boolean?,
            apiName: String?
        ) {
            continuation.resume(bizResult)
        }
    })

Get device alert list in a home

fun getWarnDeviceList(
        gid: String,
        serverType: String,
        pageNo: Int,
        pageSize: Int,
        listener: Business.ResultListener<WarnDeviceBean>
    )

Parameter description

Parameter Type Description
gid String The group to which the device belongs.
serverType String The service type.
pageNo Int The page number.
pageSize Int The number of records returned on each page.
listener Business.ResultListener<WarnDeviceBean> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().getWarnDeviceList("group123", "phone_notify_server", 1, 10,
    object : Business.ResultListener<WarnDeviceBean> {
        override fun onFailure(
            bizResponse: BusinessResponse?,
            bizResult: WarnDeviceBean?,
            apiName: String?
        ) {
            continuation.resumeWithException(
                ErrorException(
                    bizResponse?.errorCode,
                    bizResponse?.errorMsg
                )
            )
        }

        override fun onSuccess(
            bizResponse: BusinessResponse?,
            bizResult: WarnDeviceBean?,
            apiName: String?
        ) {
            continuation.resume(bizResult)
        }
    })

Notifications

Get the remaining number of times for phone call notifications

fun getAlarmPhoneTimesCount(
        listener: Business.ResultListener<AlarmTimesCount>
    )

Parameter description

Parameter Type Description
listener Business.ResultListener<AlarmTimesCount> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().getAlarmPhoneTimesCount(new Business.ResultListener<AlarmTimesCount>() {
    @Override
    public void onSuccess(BusinessResponse bizResponse, AlarmTimesCount bizResult, String apiName) {
        ServerStatus packageStatus = ServerStatus.Companion.getValue(bizResult.getPackageStatus());
        if (packageStatus == ServerStatus.NOT_PURCHASED || packageStatus == ServerStatus.EXPIRED || packageStatus == ServerStatus.USED_UP) {
            setChecked(pushType, false);
        } else {
            setChecked(pushType, result);
        }
        resultSuccess(WHAT_REFRESH, null);
    }

    @Override
    public void onFailure(BusinessResponse bizResponse, AlarmTimesCount bizResult, String apiName) {

    }
})

Get the remaining number of times for SMS notifications

fun getAlarmSMSTimesCount(
        notificationType: String,
        listener: Business.ResultListener<AlarmTimesCount>
    )

Parameter description

Parameter Type Description
notificationType String The notification type.
listener Business.ResultListener<AlarmTimesCount> The result returned from the handler function.

Example

PersonalMessageCore.newThingSmartMessagePushCore().getAlarmSMSTimesCount(ServerType.SMS.getValue(), new Business.ResultListener<AlarmTimesCount>() {
    @Override
    public void onSuccess(BusinessResponse bizResponse, AlarmTimesCount bizResult, String apiName) {
        ServerStatus packageStatus = ServerStatus.Companion.getValue(bizResult.getPackageStatus());
        if (packageStatus == ServerStatus.NOT_PURCHASED || packageStatus == ServerStatus.EXPIRED || packageStatus == ServerStatus.USED_UP) {
            setChecked(pushType, false);
        } else {
            setChecked(pushType, result);
        }
        resultSuccess(WHAT_REFRESH, null);
    }

    @Override
    public void onFailure(BusinessResponse bizResponse, AlarmTimesCount bizResult, String apiName) {

    }
})