2017-09-17 19 views
10

私は次のコードを持っていますが、たびにデフォルトのAndroidサウンドが聞こえます。Android 8通知setSound not working

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

+0

本当に誰もいませんか? – Ricardo

+0

テスト済みです。エミュレータで作業しています。 –

+0

エミュレータとデバイスで動作していません。 Android 8でテストしましたか?私はカスタムサウンドをロードしたいことに注意してください。 – Ricardo

答えて

2

私の音です。私はAudacityソフトウェアを使用しました。 あなたのサウンドファイルのサンプリングレートは22050Hzですが、私が使用するサウンドファイルは44100Hzでサンプリングされています。だから私は44100Hzにあなたのサウンドファイルのサンプリングレートを変換し、それを通知音として使用しました。今それは動作します。

問題はサウンドファイルにあります。古いAndroidバージョンで正常に動作しているため、Android Oの新しい変更点になる可能性があります。

これはリサンプルする方法です。enter image description here