Подтвердить что ты не робот

Android 8 уведомлений setSound не работает

У меня есть следующий код, но каждый раз я просто слышу звук по умолчанию для Android.

        // create  channel
        NotificationChannel channel = new NotificationChannel(ANDROID_CHANNEL_ID,
                ANDROID_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
        // Sets whether notifications posted to this channel should display notification lights
        channel.enableLights(true);
        // Sets whether notification posted to this channel should vibrate.
        channel.enableVibration(true);
        // Sets the notification light color for notifications posted to this channel
        channel.setLightColor(Color.GREEN);
        // Sets whether notifications posted to this channel appear on the lockscreen or not
        //channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        Uri uri = Uri.parse("android.resource://"+this.getPackageName()+"/" + R.raw.aperturaabductores);

        AudioAttributes att = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                .build();
        channel.setSound(uri,att);

Это мой звук pablomonteserin.es/aperturaabductores.wav

4b9b3361

Ответ 1

Я попытался увидеть разницу между вашим звуковым файлом и моим. Я использовал программное обеспечение Audacity. Ваш звуковой файл имеет частоту дискретизации 22050 Гц, в то время как звуковые файлы, которые я использую, отбираются на частоте 44100 Гц. Поэтому я преобразовал вашу частоту дискретизации звука в 44100 Гц и использовал это как звук уведомления. Теперь он работает.

Проблема со звуковым файлом. Может быть, это новое изменение в Android O, потому что он отлично работает на старой версии Android.

Вот как переконфигурировать введите описание изображения здесь