Configure push notification sound
Push notification sound refers to the ringtone played when a push notification from a vendor channel is received while the app is offline. The app only receives offline push notifications after disconnecting, and uses the system's default sound and vibration settings by default.
Remote push notifications are not triggered when the app is in the background and has not been killed by the system.
Custom ringtones can be configured for specific message types. Currently supported push providers: Huawei Push (overseas only) and FCM Push.
Select the message type
First, identify the Object Name (unique identifier) of the message content type for which you want to configure a custom ringtone. See Message Types Overview.
Prepare ringtone resource files
Package your custom sound resource file inside the application. When a user receives a push notification for that message type, the SDK automatically reads the configured file and plays the sound. The following are the file path requirements for each provider:
- Huawei Push:
/res/raw/ - FCM Push:
/res/raw/
Create a channel ID
Create a custom notification channel. You will need this Channel ID when configuring the custom push ringtone in the console.
Huawei push
Due to Huawei platform restrictions, when the data processing location is set to China on the Huawei platform, custom channels are not supported and custom ringtones cannot be used. Custom ringtones are supported after registering a Channel ID in other regions.
Call the Android SDK API from the app side to create an app-specific push notification channel. You can initialize this in MainActivity or in your Application class.
Example
private void initNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelIdKanong = "TextChannel";
String channelNameKanong = "Ringtone Kanong";
createNotificationChannel(channelIdKanong, channelNameKanong, NotificationManager.IMPORTANCE_HIGH, R.raw.music_poke_msg_incoming);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void createNotificationChannel(String channelId, String channelName, int importance, int rawSource) {
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
if (rawSource != 0) {
String uriStr = "android.resource://" + this.getPackageName() + "/" + rawSource;
Uri uri = Uri.parse(uriStr);
channel.setSound(uri, Notification.AUDIO_ATTRIBUTES_DEFAULT);
}
NotificationManager notificationManager = (NotificationManager) getSystemService(
NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
}
FCM push
See the official Android documentation on Notification Channels and the FCM Push Developer Documentation.
Configure the ringtone for each message type
After confirming that the ringtone resource file is packaged in your app, configure the custom push ringtone per message type and Channel ID in the console. Huawei Push and FCM Push are currently supported. You can configure up to 5 custom ringtones per push provider. Changes take effect 15 minutes after saving.
-
Go to the custom push ringtone page in the console and click Add under the Huawei or FCM tab.
-
Select the ApplicationID, then enter the Channel ID, message type name, and the custom ringtone file resource path.
After saving, push notifications for that message type delivered to offline users on the corresponding vendor's devices will use the specified Channel ID, and the alert ringtone will be the custom sound set when the channel was registered.