tencent cloud

Boost Engagement with Tencent RTC Free TrialFree video and chat features await!

文档反馈

即时通信 IM

自定义铃音

最后更新时间:2024-12-30 17:22:22
    Android
    iOS
    Flutter

    Android 8.0 以下系统

    1. 定制的铃音资源文件,Android 添加到工程 raw 目录下,iOS 链接进 Xcode 工程。
    2. 发送消息指定生效自定义铃音。
    restAPI
    SDK API
    请参考 restAPI 接口,比如 单发推送接口,字段示例如下:
    {
    // ...
    "OfflinePushInfo": {
    "AndroidInfo": {
    "Sound": "shake", // 不带后缀
    },
    "ApnsInfo": {
    "Sound": "apns.mp3",
    }
    }
    }
    若集成了 IM 相关产品,请您发送消息调用接口 setAndroidSound()setIOSSound()
    V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
    v2TIMOfflinePushInfo.setAndroidSound("铃音名称");
    v2TIMOfflinePushInfo.setIOSSound("铃音名称.mp3");
    
    String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,
    V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
    @Override
    public void onProgress(int progress) {
    
    }
    
    @Override
    public void onError(int code, String desc) {
    
    }
    
    @Override
    public void onSuccess(V2TIMMessage v2TIMMessage) {
    
    }
    });
    注意:
    IMSDK 6.1.2155 及以上版本支持。
    接口支持华为、小米、FCM 和 APNS。

    Android 8.0 及以上系统

    华为 和 ANPS

    华为、APNS 可调用上面接口来设置离线推送铃音提示。

    OPPO

    1.将定制的铃音资源文件放在工程资源的 raw 目录下,然后通过以下方式创建通知 channel。
    // 自定义创建示例
    if (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://包名/raw/private_ring"
    notificationChannel.setSound(Uri.parse("sound"), null);
    nm.createNotificationChannel(notificationChannel);
    }
    2.使用创建的 channel。
    发送消息指定 channelID 生效自定义铃音,接口设置参考如下,控制台设置见证书的 channelID 字段,两者设置一个即可。
    restAPI
    SDK API
    请参考 restAPI 接口,比如 单发推送接口,字段示例如下:
    {
    // ...
    "OfflinePushInfo": {
    "AndroidInfo": {
    "OPPOChannelID": "test_OPPO_channel_id",
    }
    }
    }
    若集成了 IM 相关产品,请您发送消息调用接口 setAndroidOPPOChannelID

    小米

    1.登录厂商控制台 创建 channel 和配置,其中铃音文件需要添加到您本地 Android Studio 工程的 raw 目录下。
    
    2.发送消息指定 channelID 生效自定义铃音,接口设置参考如下,控制台设置见证书的 channelID 字段,两者设置一个即可。
    restAPI
    SDK API
    请参考 restAPI 接口,比如 单发推送接口,字段示例如下:
    {
    // ...
    "OfflinePushInfo": {
    "AndroidInfo": {
    "XiaoMiChannelID": "test_XiaoMi_channel_id",
    }
    }
    }
    若集成了 IM 相关产品,详情请参见 setAndroidXiaoMiChannelID
    V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
    v2TIMOfflinePushInfo.setAndroidXiaoMiChannelID("厂商申请的 channel ID");
    
    String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,
    V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
    @Override
    public void onProgress(int progress) {
    TUIChatUtils.callbackOnProgress(callBack, progress);
    }
    
    @Override
    public void onError(int code, String desc) {
    TUIChatUtils.callbackOnError(callBack, TAG, code, desc);
    }
    
    @Override
    public void onSuccess(V2TIMMessage v2TIMMessage) {
    
    }
    });

    FCM

    1.将定制的铃音资源文件放在工程资源的 raw 目录下,然后通过以下方式创建通知 channel。
    // 自定义创建示例
    if (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://包名/raw/private_ring"
    notificationChannel.setSound(Uri.parse("sound"), null);
    nm.createNotificationChannel(notificationChannel);
    }
    2.发送消息指定自定义铃音的 channelID,
    restAPI
    SDK API
    请参考 restAPI 接口,比如 单发推送接口,字段示例如下:
    {
    // ...
    "OfflinePushInfo": {
    "AndroidInfo": {
    "GoogleChannelID": "test_Google_channel_id",
    }
    }
    }
    若集成了 IM 相关产品,详情请参见 setAndroidFCMChannelID
    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>() {
    @Override
    public void onProgress(int progress) {
    TUIChatUtils.callbackOnProgress(callBack, progress);
    }
    
    @Override
    public void onError(int code, String desc) {
    TUIChatUtils.callbackOnError(callBack, TAG, code, desc);
    }
    
    @Override
    public void onSuccess(V2TIMMessage v2TIMMessage) {
    
    }
    });
    注意:
    IMSDK 7.0.3754 及以上版本支持。
    FCM 自定义铃声或者设置 ChannnelID 仅支持证书模式。
    
    1. 请在发送消息的时候设置 OfflinePushInfo 的 iOSSound 字段, iOSSound 传语音文件名。
    restAPI
    SDK API
    请参考 restAPI 接口,比如 单发推送接口,字段示例如下:
    {
    // ...
    "OfflinePushInfo": {
    "ApnsInfo": {
    "Sound": "apns.mp3",
    }
    }
    }
    若集成了 IM 相关产品,请您发送消息参考:
    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) {
    
    }];
    说明:
    离线推送声音设置(仅对 iOS 生效), 当 iOSSound = kIOSOfflinePushNoSound,表示接收时不会播放声音。
    当 iOSSound = kIOSOfflinePushDefaultSound,表示接收时播放系统声音。
    如果要自定义 iOSSound,需要先把语音文件链接进 Xcode 工程,然后把语音文件名(带后缀名)设置给 iOSSound。
    iOS 自定义铃音长度不能超过 30s。
    2. 请在发送消息的时候设置 OfflinePushInfo 的 AndroidSound 字段, AndroidSound 传语音文件名。
    restAPI
    SDK API
    请参考 restAPI 接口,比如 单发推送接口,字段示例如下:
    {
    "OfflinePushInfo": {
    "AndroidInfo": {
    "Sound": "shake", // 不带后缀
    "OPPOChannelID": "test_OPPO_channel_id",
    "XiaoMiChannelID": "test_XiaoMi_channel_id",
    "OPPOChannelID": "test_OPPO_channel_id",
    "GoogleChannelID": "test_Google_channel_id"
    },
    "ApnsInfo": {
    "Sound": "apns.mp3"
    }
    }
    }
    若集成了 IM 相关产品,请您发送消息参考:
    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) {
    
    }];
    说明:
    离线推送声音设置(仅对 Android 生效, 仅 imsdk 6.1 及以上版本支持) 只有华为和谷歌手机支持设置铃音提示。
    小米铃音设置请您参见:服务端 Java SDK 文档
    如果要自定义 AndroidSound,需要先把语音文件放到 Android 工程的 raw 目录中,然后把语音文件名(不需要后缀名)设置给 AndroidSound。
    注意:
    接口支持华为、小米、FCM 和 APNS。
    定制的铃音资源文件,Android 添加到工程 raw 目录下,iOS 链接进 Xcode 工程。
    请在发送消息的时候设置 offlinePushInfo 的 iOSSoundandroidSound 字段。
    restAPI
    SDK API
    请参考 restAPI 接口,比如 单发推送接口,字段示例如下:
    {
    // ...
    "OfflinePushInfo": {
    "AndroidInfo": {
    "Sound": "shake", // 不带后缀
    "OPPOChannelID": "test_OPPO_channel_id",
    "XiaoMiChannelID": "test_XiaoMi_channel_id",
    "OPPOChannelID": "test_OPPO_channel_id",
    "GoogleChannelID": "test_Google_channel_id"
    },
    "ApnsInfo": {
    "Sound": "apns.mp3"
    }
    }
    }
    若集成了 IM 相关产品,请在调用 sendMessage 发送消息的时候设置 offlinePushInfoiOSSoundandroidSound 字段。
    具体各厂商配置,请参阅 Android 及 iOS 模块的内容。调用的方法均在 Flutter 版本的 IM SDK 中有同名方法。

    

    

    

    
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持
    Hong Kong, China
    +852 800 906 020 (Toll Free)
    United States
    +1 844 606 0804 (Toll Free)
    United Kingdom
    +44 808 196 4551 (Toll Free)
    Canada
    +1 888 605 7930 (Toll Free)
    Australia
    +61 1300 986 386 (Toll Free)
    EdgeOne hotline
    +852 300 80699
    More local hotlines coming soon