2017-09-17 34 views
10

Tôi có mã sau đây nhưng mỗi lần tôi chỉ nghe âm thanh android mặc định.Thông báo Android 8 được đặtSound không hoạt động

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

Đây là âm thanh của tôi pablomonteserin.es/aperturaabductores.wav

+0

Không ai, thực sự? – Ricardo

+0

Đã kiểm tra. làm việc trong trình mô phỏng. –

+0

Không hoạt động trong trình mô phỏng và thiết bị của tôi. Bạn đã thử nghiệm trên Android 8 chưa ?. Xin lưu ý rằng tôi muốn tải âm thanh tùy chỉnh. – Ricardo

Trả lời

2

Tôi cố gắng để thấy sự khác biệt giữa các tập tin âm thanh của bạn và của tôi. Tôi đã sử dụng phần mềm Audacity. Tệp âm thanh của bạn có tốc độ lấy mẫu 22050Hz trong khi các tệp âm thanh tôi sử dụng được lấy mẫu tại 44100Hz. Vì vậy, tôi đã chuyển đổi tỷ lệ lấy mẫu tập tin âm thanh của bạn thành 44100Hz và sử dụng nó làm âm thanh thông báo. Bây giờ nó hoạt động.

Sự cố xảy ra với tệp âm thanh. Có thể đó là thay đổi mới trong Android O vì nó hoạt động tốt trên phiên bản Android cũ hơn.

Đây là cách để lấy lại mẫu - enter image description here

Các vấn đề liên quan