Advanced configuration APIs

更新时间:
复制 MD 格式

Set the notification sound

Set the file path for the push notification sound. For Android 8.0 and later, you must configure the sound using a NotificationChannel.

Important
  • If you do not call this API, the system retrieves the resource file with the ID R.raw.alicloud_notification_sound by default.

  • If the specified sound file cannot be found, the device's default message sound is used.

setNotificationSoundFilePath

API definition

void setNotificationSoundFilePath(String filePath)

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

filePath

String

Yes

A string that can be parsed by a URI.

Set the notification bar icon

Set the bitmap resource for the push notification icon.

Important
  • If you do not call this API, the system retrieves the resource file with the ID R.drawable.alicloud_notification_largeicon by default.

  • If the specified icon file cannot be found, the app's launcher icon is used.

setNotificationLargeIcon

API definition

void setNotificationLargeIcon(Bitmap icon)

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

icon

Bitmap

Yes

The bitmap resource for the icon.

Set the status bar icon

Set the resource ID for the push notification status bar icon.

Important
  • If you do not call this API, the system retrieves the resource file R.drawable.alicloud_notification_smallicon by default.

  • If the specified resource file ID cannot be found, the app's launcher icon is used.

setNotificationSmallIcon

API definition

void setNotificationSmallIcon(int iconId)

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

iconId

int

Yes

The resource ID for the icon.

Set the Do Not Disturb period

Set a Do Not Disturb (DND) period to filter all notifications and messages.

Important
  • You can only set the DND period once. If you call the API multiple times, only the last setting takes effect.

  • For SDK versions earlier than V2.3.5, you can cancel the DND feature by setting the period to 00:00-00:00.

  • To enable DND for the entire day, set the period to "00:00-23:59".

  • The DND setting does not affect Mi pop-up notifications.

setDoNotDisturb

API definition

void setDoNotDisturb(int startHour, int startMinute, int endHour, int endMinute, CommonCallback callback)

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

startHour

int

Yes

The start hour of the DND period in 24-hour format. Valid values: 0 to 23.

startMinute

int

Yes

The start minute of the DND period. Valid values: 0 to 59.

endHour

int

Yes

The end hour of the DND period in 24-hour format. Valid values: 0 to 23.

endMinute

int

Yes

The end minute of the DND period. Valid values: 0 to 59.

callback

int

Yes

The callback class for setting the DND period. The onSuccess method is called on success, and the onFailed method is called on failure.

Disable the Do Not Disturb feature

Disable the Do Not Disturb (DND) feature.

Important
  • The DND feature is disabled by default.

  • There is no specific API to enable the DND feature. It is automatically enabled when you set a DND period.

  • This feature is supported in SDK V2.3.5 and later.

closeDoNotDisturbMode

API definition

void closeDoNotDisturbMode()

Class

CloudPushService

Clear all notifications

Clears all notifications created by the Push SDK. You cannot use this API to clear notifications from third-party channels.

Important
  • To clear a specific notification, retrieve the notification ID from the onNotification callback and then clear the notification.

  • This feature is supported in SDK V2.3.7 and later.

clearNotifications

API definition

void clearNotifications()

Class

CloudPushService

Set the large icon download monitoring callback

Set a monitoring callback to monitor the download status of large icons and images and identify the cause of any failures.

Important
  • This feature is supported in SDK v3.8.2 and later.

setLargeIconDownloadListener

API definition

void setLargeIconDownloadListener(OnLargeIconDownloadListener listener)

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

listener

OnLargeIconDownloadListener

Yes

The download callback.

Set notification grouping

Groups multiple notifications. By default, notifications are not grouped.

Important
  • This feature is supported in SDK v3.8.2 and later.

setNotificationShowInGroup

API definition

void setNotificationShowInGroup(boolean inGroup)

Class

CloudPushService

Parameters

Parameter

Type

Required

Description

inGroup

boolean

Yes

  • If set to true, notifications are collapsed.

  • false: Do not group notifications.

In-app channel control APIs

Important

  • Supported in SDK V3.7.4 and later.

  • These APIs are for scenarios that require strict connection control. They are not needed for typical mobile phone scenarios.

The control APIs allow you to check the in-app channel connection status, reconnect, reset the channel, and listen for connection status changes.

isConnected

Checks if the in-app channel is connected.

API definition

boolean isConnected()

Class

PushControlService

Return value

Type

Description

boolean

  • true: Connected.

  • false: Not connected.

setConnectionChangeListener

The APIs for listening to and checking the connection status help your business logic determine the connection state.

API definition

void setConnectionChangeListener(ConnectionChangeListener listener)

Class

PushControlService

Parameters

Parameter

Type

Required

Description

listener

ConnectionChangeListener

Yes

The listener callback interface.

Code examples

PushServiceFactory.getPushControlService()
    .setConnectionChangeListener(object : ConnectionChangeListener {
        override fun onConnect() {}
        override fun onDisconnect(code: String, msg: String) {}
    })
PushServiceFactory.getPushControlService().setConnectionChangeListener(new PushControlService.ConnectionChangeListener() {
	@Override
	public void onConnect() {
				
	}

	@Override
	public void onDisconnect(String code, String msg) {

	}
});

reconnect

Use the reconnect API to attempt a reconnection if your business logic detects that the connection is down and has not automatically reconnected.

API definition

void reconnect()

Class

PushControlService

reset

Use the reset API to reset the internal initialization state of the SDK. If the connection does not recover after a reconnection attempt, you can call this API and then call the SDK registration API to re-register the push channel.

API definition

void reset()

Class

PushControlService