2017-09-17 3 views
10

J'ai le code suivant mais chaque fois que j'entends le son android par défaut.Android 8 notifications setSound ne fonctionne pas

 // 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); 

Ceci est mon son pablomonteserin.es/aperturaabductores.wav

+0

Personne, vraiment? – Ricardo

+0

Testé. travailler en émulateur. –

+0

Ne fonctionne pas dans mon émulateur et mon appareil non plus. Avez-vous testé sur Android 8 ?. Veuillez noter que je veux charger un son personnalisé. – Ricardo

Répondre

2

J'ai essayé de voir la différence entre votre fichier son et le mien. J'ai utilisé le logiciel Audacity. Votre fichier audio a un taux d'échantillonnage de 22050Hz tandis que les fichiers audio que j'utilise sont échantillonnés à 44100Hz. J'ai donc converti le taux d'échantillonnage de votre fichier audio à 44100Hz et l'ai utilisé comme son de notification. Maintenant ça marche.

Le problème est avec le fichier son. Peut-être que c'est un nouveau changement dans Android O parce qu'il fonctionne bien sur la version Android plus ancienne.

Voici comment resample- enter image description here