小编Ang*_*iev的帖子

适用于 Android 11 的 NotificationChannel 的自定义声音不起作用

我有自定义声音的推送通知,直到 android 10。从 Android 11 开始,当通知显示为下拉样式时,附加到通知通道的声音停止播放。当它显示为全屏活动时,它会起作用。

这是如何创建通知通道的示例源代码

private void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

    String channelId = "media_playback_channel_v_01_1_sound"
    String channelName = "Channel High"
        NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription("My custom sound");
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        AudioAttributes.Builder builder = new AudioAttributes.Builder();
        builder.setUsage(AudioAttributes.USAGE_NOTIFICATION);
    String basePath = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.alarm_sound);
    Uri alarmSound = Uri.parse(basePath); …
Run Code Online (Sandbox Code Playgroud)

android-notifications notification-channel android-11

7
推荐指数
1
解决办法
570
查看次数