Hi,
I am having issues with playing a custom sound on android after I upgraded to API 26. The sound worked before this upgrade and currently works in iOS.
I am using RN 0.56.1 and have updated the package to 3.1.2, added a channel name and description in my android manifest as per the readme (this issue occured in 3.1.1 too).
The code below is used to schedule a local notification:
PushNotification.localNotificationSchedule({
id: id,
number: 0,
userInfo: {
id: id,
...payload,
},
title: "My title",
message: "My message",
date: moment().add(30, 'seconds').toDate(),
soundName: 'alarm.mp3',
repeatType: 'minute',
data: JSON.stringify(payload),
priority: "max",
importance: "max",
visibility: "public",
autoCancel: false,
});
alarm.mp3 exists in /app/src/main/res/raw/ folder and is 30 seconds long.
I am having the same issue, but with remote notification coming from Firebase
This fork https://github.com/MaximusBaton/react-native-push-notification has been the only one that works for me. Unfortunately it's behind a few versions, but it'll have to do for now until we can get an official fix.
I was able to get the sound to play but had to modify the Android code for the plugin, let me know if you need it
Yes, please post it @spencerfontein!
@spencerfontein can you post your solution? thx
@spencerfontein pleeeeeease. Your help would be gratefully appreciated :)
Hi @spencerfontein, like others I'm experiencing that same issue.
If you can share your solution it will be amazing!
I am experiencing this since I had to upgrade the to SDK 26. To see what happens, I added a log to RNPushNotificationHelper.java after notification.build(): Log.i(LOG_TAG, "Info: " + info)
On Android 7 it shows:
12-11 11:07:14.466 9084 9345 I RNPushNotification: Info: Notification(pri=1 contentView=null vibrate=[0,300] sound=android.resource://br.com.getrak.gconnect/2131427328 defaults=0x4 flags=0x10 color=0xffff6600 category=call vis=PRIVATE)
On Android O and above it shows:
12-11 11:27:59.444 32608 32655 I RNPushNotification: Info: Notification(channel=rn-push-notification-channel-id pri=1 contentView=null vibrate=null sound=null defaults=0x4 flags=0x10 color=0xffff6600 category=call vis=PRIVATE)
By now I have the following:
build.gradle:
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 21
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
googlePlayServicesVersion = "+"
}
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com;.xxx.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="MyApp"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="MyApp Alerts"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService" />
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
Be it a loca notification (schedules or not) or remote notification, only the default sound is played on Android 8.0+.
OK, I found this ref to the solution very helpful...
I just installed
npm install --save https://github.com/MaximusBaton/react-native-push-notification.git
and it's replaced the original module and working well on Android 8+.
https://github.com/MaximusBaton/react-native-push-notification.git was forked on July 4, so its a little behind on the original
Thank you @Gys, I saw that but currently, for my purpose, it's good enough until the original will be adopted that fix.
Is the Notification sound issue is resolved in android? I see the the sound permission in notification is disabled. did anybody knows, how to resolve this?
PR #1042 seems to fix the problem.
I had this problem until I used a fork that merged this.
@zo0r PR https://github.com/zo0r/react-native-push-notification/pull/1042 is very much needed. Could you please do something to make it merged?
I was able to get the sound to play but had to modify the Android code for the plugin, let me know if you need it
i need it if you can give me
Its been a while but if you need the code, maybe I can assist. let me know
Hi;
Sounds are fixed on 3.4.0
@Dallas62 I don't think they're fixed in 3.4.0. I noticed that in Settings -> Apps -> Notifications, two channels are created with same names and descriptions: One with the sound and one without. However, no sound plays on Android.
UPDATE: I could just be that it doesn't play on the Emulator. Will check with real device later. However, I don't think there should be two channels in Settings?
Hi @rikur
Unfortunately, without a huge refactoring, sounds and notification can鈥檛 be handled properly.
Actually there is no real channel management, so each time notification settings change (sound, importance, vibration) a channel will be created.
In order to receive notification without posting local notification (to create the channel) a default channel has been created.
This is clearly not the right way the library should work. But to avoid huge refactoring (applications and library) it鈥檚 a workaround.
I will try to find time to change this but probably not in a short period of time.
remove .mp3
Then, it works!!!!
Most helpful comment
@zo0r PR https://github.com/zo0r/react-native-push-notification/pull/1042 is very much needed. Could you please do something to make it merged?