Custom Definition Ringtone
Systems below Android 8.0
1. Custom ringtone resource files for Android should be added to the project's raw directory; for iOS, link them into the Xcode project.
2. Send messages with specified custom ringtone.
Please refer to the restAPI interface, such as single push interface, with the following field example:
{// ..."OfflinePushInfo": {"AndroidInfo": {"Sound": "shake", // without suffix},"ApnsInfo": {"Sound": "apns.mp3",}}}
If you have integrated IM related products, please send messages using the setAndroidSound() and setIOSSound() interfaces.
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidSound("Ringtone Name");v2TIMOfflinePushInfo.setIOSSound("Ringtone Name.mp3");String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {}@Overridepublic void onError(int code, String desc) {}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
Note:
Supported in IMSDK v6.1.2155 or above.
The interface supports Huawei, Xiaomi, FCM, and APNS.
Android 8.0 and later versions
Huawei and APNs
Huawei and APNS can use the above interfaces to set offline push ringtone prompt.
OPPO
1 Place the customized ring tone resource file in the raw directory of the project resources, then create a notification channel as follows.
// Custom creation exampleif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);NotificationChannel notificationChannel =new NotificationChannel("channelId", "channelName", NotificationManager.IMPORTANCE_HIGH);notificationChannel.enableLights(true);notificationChannel.enableVibration(true);notificationChannel.setShowBadge(true);notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);// "android.resource://package_name/raw/private_ring"notificationChannel.setSound(Uri.parse("sound"), null);nm.createNotificationChannel(notificationChannel);}
2 Use the created channel.
Send messages specifying the channelID to take effect with the custom ring tone. Refer to the following interface settings. For console settings, see the channelID field in the certificate. Only one of the two settings is needed.
Please refer to the restAPI interface, such as single push interface, with the following field example:
{// ..."OfflinePushInfo": {"AndroidInfo": {"OPPOChannelID": "test_OPPO_channel_id",}}}
If you have integrated IM related products, please send messages using the setAndroidOPPOChannelID interface.
Mi
1 Log in to the manufacturer console to create channel and configuration, where the ring tone file needs to be added to the raw directory of your local Android Studio project.
Send messages specifying the channelID to take effect with the custom ring tone. Refer to the following interface settings. For console settings, see the channelID field in the certificate. Only one of the two settings is needed.
Please refer to the restAPI interface, such as single push interface, with the following field example:
{// ..."OfflinePushInfo": {"AndroidInfo": {"XiaoMiChannelID": "test_XiaoMi_channel_id",}}}
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidXiaoMiChannelID("Channel ID Applied by Manufacturer");String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {TUIChatUtils.callbackOnProgress(callBack, progress);}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
FCM
1 Place the customized ring tone resource file in the raw directory of the project resources, then create a notification channel as follows.
// Custom creation exampleif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationManager nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);NotificationChannel notificationChannel =new NotificationChannel("channelId", "channelName", NotificationManager.IMPORTANCE_HIGH);notificationChannel.enableLights(true);notificationChannel.enableVibration(true);notificationChannel.setShowBadge(true);notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);// "android.resource://package_name/raw/private_ring"notificationChannel.setSound(Uri.parse("sound"), null);nm.createNotificationChannel(notificationChannel);}
Send messages specifying the channelID with a custom ringtone.
Please refer to the restAPI interface, such as single push interface, with the following field example:
{// ..."OfflinePushInfo": {"AndroidInfo": {"GoogleChannelID": "test_Google_channel_id",}}}
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidFCMChannelID(PrivateConstants.fcmPushChannelId);String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {TUIChatUtils.callbackOnProgress(callBack, progress);}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
Note:
Supported in IMSDK v7.0.3754 or above.
FCM custom alert tones or setting ChannelID are only supported in certificate mode.
1. Set the iOSSound field of OfflinePushInfo when sending messages. Pass the voice file name to iOSSound.
Please refer to the restAPI interface, such as single push interface, with the following field example:
{// ..."OfflinePushInfo": {"ApnsInfo": {"Sound": "apns.mp3",}}}
If you have integrated IM related products, please refer to sending messages.
V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"push title";pushInfo.iOSSound = @"phone_ringing.mp3"; // your voice file's name[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{} fail:^(int code, NSString *msg) {}];
Note:
Offline push notification sound settings (effective only for iOS), when `iOSSound = kIOSOfflinePushNoSound`, it indicates no sound will be played upon receiving.
When `iOSSound = kIOSOfflinePushDefaultSound`, it indicates the system sound will be played upon receiving.
To customize `iOSSound`, you first need to link the audio file into the Xcode project, and then set the audio filename (including the extension) to `iOSSound`.
iOS Custom Ringtone length cannot exceed 30s.
2. Set the
AndroidSound
field of OfflinePushInfo when sending messages. Pass the voice file name to AndroidSound
.Please refer to the restAPI interface, such as single push interface, with the following field example:
{"OfflinePushInfo": {"AndroidInfo": {"Sound": "shake", // without suffix"OPPOChannelID": "test_OPPO_channel_id","XiaoMiChannelID": "test_XiaoMi_channel_id","OPPOChannelID": "test_OPPO_channel_id","GoogleChannelID": "test_Google_channel_id"},"ApnsInfo": {"Sound": "apns.mp3"}}}
If you have integrated IM related products, please refer to sending messages.
V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"push title";pushInfo.AndroidSound = @"phone_ringing"; // your voice file's name[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{} fail:^(int code, NSString *msg) {}];
Note:
Offline push notification sound settings (effective only for Android, supported only in imsdk 6.1 and above) are supported only on Huawei and Google phones for setting ringtone prompts.
For Xiaomi ringtone settings, please refer to: Server-side Java SDK documentation.
To customize `AndroidSound`, you first need to place the audio file in the raw directory of the Android project, and then set the `AndroidSound` with the audio filename (without the extension).
Note:
The interface supports Huawei, Xiaomi, FCM, and APNS.
Custom ringtone resource files for Android should be added to the project's raw directory; for iOS, link them into the Xcode project.
Set the
iOSSound
and androidSound
fields of offlinePushInfo when sending messages.Please refer to the restAPI interface, such as single push interface, with the following field example:
{// ..."OfflinePushInfo": {"AndroidInfo": {"Sound": "shake", // without suffix"OPPOChannelID": "test_OPPO_channel_id","XiaoMiChannelID": "test_XiaoMi_channel_id","OPPOChannelID": "test_OPPO_channel_id","GoogleChannelID": "test_Google_channel_id"},"ApnsInfo": {"Sound": "apns.mp3"}}}
If you have integrated im related products, set the offlinePushInfo's
iOSSound
and androidSound
fields when calling sendMessage to send messages.For specific manufacturer configurations, refer to the content of the Android and iOS modules. The methods to call are all named the same in the Flutter version of the IM SDK.