Android 8 (API 26) Custom sound not working
Custom music is not working on my emulator Android 8.0 (API26). It's every time playing the default one. I have the latest version of this library, installed directly from this repository.
The same code works fine on API 19 - 25.
Is there any workaround to fix it?
So, I spent a whole day making a research (being a non-java programmer).
First of all, this behavior is related to API 26 (Oreo) and higher only. In these android versions notifications channels are needed (what actually was implemented in this library)
Ref 1 says:
When you target Android 8.0 (API level 26), you must implement one or more notification channels. If your targetSdkVersion is set to 25 or lower, when your app runs on Android 8.0 (API level 26) or higher, it behaves the same as it would on devices running Android 7.1 (API level 25) or lower.
However, this somehow didn't actually help me ;(
Ref 2. This answer moved the stone! So the main idea here is to set the channels's sound. BUT! This leads to impossibility of changing the notification sound to another :(( Accompanying link
So my idea now to create a new channel each time I need to play a custom sound. This can be done in checkOrCreateChannel method. But still not working....
So, I got it working: https://github.com/MaximusBaton/react-native-push-notification/commit/8cc8376998fb20dba9f3d47642c160d694294af9
Idea: we create several channels for each sound with custom name:
tmpSettings['channelName'] = alarm.channelName || 'Default alarm notification';
...
// Schedule!
this.localNotificationSchedule(tmpSettings);
NB: This solutions suits my needs, however may not yours.
Anyway will be waiting for a better solution and thank you DEVs for a great library!
BTW, a very good approach found here: https://stackoverflow.com/a/46862503/4088526
Thanks a lot.
I had the same problem and your solution is useful. Do you PR it ?
Hope this improvement can be merged to next version as soon as possible.
Thanks a lot. I had the same problem and your solution is useful. Do you PR it ? Hope this improvement can be merged to next version as soon as possible.
I too hope they make the fix for this issue available as soon as possible.