Нет звука в канале уведомлений для целевого API 26 - PullRequest
0 голосов
/ 25 ноября 2018

Я создал канал уведомлений следующим образом:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        if (notificationManager == null)
            notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationChannel channel = notificationManager.getNotificationChannel(notificationChannelId);
        if (channel == null) {
            channel = new NotificationChannel(notificationChannelId, channelName, importance);
            channel.enableLights(true);
            channel.enableVibration(true);

            if (sound == null)
                sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .build();
            channel.setSound(sound, audioAttributes);
            notificationManager.createNotificationChannel(channel);
        }
        builder = new NotificationCompat.Builder(context, notificationChannelId);
    }

Когда я запускаю его в эмуляторе с API 26, я получаю уведомления без звука.В журналах я вижу

W / Уведомление: использование типов потоков не рекомендуется для операций, отличных от управления громкостью.Смотрите документацию по setSound (), чтобы узнать, что использовать вместо этого с android.media.AudioAttributes для определения вашего варианта использования

, что странно, так как я уже использую каналы уведомлений.Я отследил место, где это написано, и нашел ctor NotificationCompatApi26.Builder, где setSound называется

new Notification.Builder(context, channelId).setSound(n.sound, n.audioStreamType)

После этого я проиграл.Любая идея, почему у меня нет звука в уведомлении?

Компиляция и целевой SDK оба 26.

...