NotificationChannel playing wrong sound in Oreo

爱⌒轻易说出口 提交于 2019-12-13 13:15:59

问题


I have this weird problem with NotificationChannel sound in devices running Android Oreo.

Lets say i have two sound files in my project raw directory:

a.mp3
c.mp3

Then on first installation of an app i assign those sounds to different notification channels using their uri (for example):

android.resource://myapp/2131558403 (for sound a.mp3)
android.resource://myapp/2131558404 (for sound c.mp3)

At this point everything works as expected. Problem appears when i start adding new sounds (in front or in the middle):

a.mp3
B.mp3 <- new file
c.mp3

Resource IDs then change for the files accordingly:

android.resource://myapp/2131558403 (for sound a.mp3)
android.resource://myapp/2131558404 (for sound B.mp3)
android.resource://myapp/2131558405 (for sound c.mp3)

So at this point my second notification channel starts playing B.mp3 sound file instead of c.mp3 because it was initialized with android.resource://myapp/2131558404 uri.

Resource id for for c.mp3 has shifted after compiling an app with new sound file.

So what would be solution for this problem since i can not modify notification channel after it was created.

Most obvious solution would be not to add new files in the middle of the old ones but could be forgotten.

Maybe i could delete old channel and add it again with new id?

Or is there a way to make raw files to have constant resource id?


回答1:


NotificationChannels are persistent. When making such changes, you would need to give the channel a different ID for the change to be picked up.



来源:https://stackoverflow.com/questions/48781986/notificationchannel-playing-wrong-sound-in-oreo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!