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?
NotificationChannels are persistent. When making such changes, you would need to give the channel a different ID for the change to be picked up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With