Hi lovely community,
i am having trouble to understand the behaviour of push notifications on android devices.
Setting up this library and following all instructions, I have the iOS version perfectly working as I would expect it.
For android I get a confusing behaviour, at least for me its seems that way.
Registration and local notification seem to work perfectly.
For Remote Notifications I get the following behaviour:
App in foreground: Notification with PopUp and Vibration and Sound and icon in status bar (as expected)
App in background: Notification only gives Sound and show icon in status bar. No Popping Up. No Vibration.
After looking for quite some time. I just can't find the error.
I want a push notifications service that works just like a message service.
What exactly am I missing? I don't think its is supposed to work that way...
If necessary I can provide code.
Hi,
Did you specify the right channel for notifications ?
The channel define behavior of notifications in Android.
So, first, based on your answer, I assume my expected behaviour of this library is correct. I do have some things wrong then.
Yes, good point about the channels. Ive been trying to work on/with that. Maybe I messed up.
So these are the artifacts left of AndroidManifest.xml (regarding the channels).
`
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize">
<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" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.rn-push-notification-channel-id-4-300" android:value="APP NAME NOTIFICATION" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.rn-push-notification-channel-id-4-300" android:value="SENDS NOTIFICATIONS ABOUT YOUR APP" />
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="true" />
<!-- Change the value to false if you don't want the creation of the default channel -->
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default" android:value="true" />
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@color/white" /> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<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.RNPushNotificationListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="APP NAME NOTIFICATION" />
</application>
`
If understood correctly, I don't need to define a channel for sending notifications, I only need one channel and the default one should be used. Correct?
So is this implementation correct?
Edit:
if App in background
onNotification: function (notification) {
console.log('NOTIFICATION:', notification);
// process the notification
notification.finish(PushNotificationIOS.FetchResult.NoData);
}
is not being triggered, only if i press the notification in Notification Center.
and further, the function
PushNotification.getChannels(function (channel_ids) {
console.log(channel_ids); // ['channel_id_1']
});
returns empty array.
Is this behaviour correct?
Thx
In you Manifest, you are not using the right channel value, you provide the channel name when the channel id is expected.
Also the channel id you are using doesn't have a sound or vibration (look at the readme).
In Firebase server-side, you can define the channel id, if needed
Thank you so far. I guess I need a little bit more help here.
Lets say I just want to have/use a/the default channel.
Is changing to
`
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize">
<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" />
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="true" />
<!-- Change the value to false if you don't want the creation of the default channel -->
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default" android:value="true" />
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@color/white" /> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<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.RNPushNotificationListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
`
meaning deleting
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.rn-push-notification-channel-id-4-300" android:value="APP NAME NOTIFICATION" />
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.rn-push-notification-channel-id-4-300" android:value="SENDS NOTIFICATIONS ABOUT YOUR APP" />
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="APP NAME NOTIFICATION" />
Going to work?
Do I need to create another channel? Not really clear from the docs...
Ive tried the above mentioned solution, but I am still having the same problem.
Or am I just sending the wrong message from server?
Thank you
You can:
Then defined it as default channel for firebase:
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="MY CHANNEL ID" />
Or set the channelId as a parameter of Firebase (server-side, refer to firebase documentation for that).
Thank you, but still having problems...
is this correct now?
`
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize">
<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" />
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="true" />
<!-- Change the value to false if you don't want the creation of the default channel -->
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default" android:value="true" />
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@color/white" /> <!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<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.RNPushNotificationListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="rn-push-notification-channel-id-4-300" />
</application>
`
if this is correct now? Do I have to specify this channel now in the notification message now? Or is the default one used.
sry for these questions ... but I am confused ..
thank you
So I've been trying many different things as well, and still can't get it to work.
I've read that react-native-natvigation (which Im using) might cause some problems due to its lifecycle management.
Anyone with similar problem that can help?
Did you try to setup the example project to see if it's occurring on it ?
Then investigate what cause the problem.
I did try the example. I get the following behaviour:
Remote Notifications keep showing up in the status bar, but do not pop up.
If app is closed via task manager. No notifications arrive at all. This problem was not previously observed.
Creating channels via button returns: "createChannel returned 'false'"
I don't know what is wrong. Do I need to include a special property in the payload of my message to make it work maybe?
What is your Android SDK version ?
Thank you Dallas62 for helping me out. Its been a hard fight so far for me.
SDK is interesting. I am using SDK 29.
My physical device still has Android 5.0 (old Device), this might actually be the reason why its not working.
But I am also trying on a virtual devices and I am getting the same behaviour as already described above. Are Pop Up's supported on virtual devices?
Did you copy some part of the example application, or did you run the entire example project ?
The notification should pop-up with all your Android versions.
I ran the entire example project. No modifications besides my google-service.json ...
And with simulator and real devices, you don't have channels ?
You should be able to see channels in app settings.
for the the real device I get an empty array. For the virtual device I get an array with channel id.
And its not about the payload? I can control color, and sound, just not the popping ... ?
This is the result of the example project ?
What's the value of the channel id ?
The main reason of "not popping up" is that the notification doesn't have a channel or settings of the channel.
The value is: rn-push-notification-channel-id-4-default-300 .
So please correct me if im wrong, but taking the example app, unmodified besides the google-service.json, should give a popping message, not considering any channel in the payload, since it should use the default one. Right?
Although I tried sending messages with channel id, it should still give me a pop up, if I don't explicitly name the channel. Is this correct?
Edit: Ok so after some messing around, I finally got it to work on the virtual device. My Payload was just simply incorrect, indeed, the channel id was wrong.
Anyway, for my physical device, I am still having the issues. (Android 6.0.1 btw, not 5.0.0) I can not create any channels and I assume this is the problem...
So what might be the cause?
The example project should work whitout change (expect google-service.json).
You can try to add in AndroidManifest:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="rn-push-notification-channel-id-4-default-300" />
This is not the exact same value as your previous comments.
Yes, you are right. It is not the same value. Due to trying I ended up with giving you the output which does not correspond to the given info above.
After giving it more tries I couldn't get it to work on my device. It runs perfectly on virtual device, though, and I checked it on another (newer) Device. It also runs smoothly on the other device. I am fine with that. I guess my device is the problem.
Thank you very much for your help.
@fileMasterDeluxe it seems like Android 7 might be the root of this issue: https://forums.expo.io/t/android-7-does-not-show-push-notification-android-8-and-ios-works-well/19292
Thx, this gives at least I lil bit of sunlight to this problem.
@Dallas62 , i am also unable to get pop up on receiving notification. Trying on android 10
Hey, this work like a charm. I hope this can help you
AndroidManifest.xml
...
<meta-data
android:name="com.dieam.reactnativepushnotification.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />
...
And in android/app/src/main/res/values/strings.xml
<string name="default_notification_channel_id" translatable="false">fcm_default_channel</string>
I did try the example. I get the following behaviour:
Remote Notifications keep showing up in the status bar, but do not pop up.
If app is closed via task manager. No notifications arrive at all. This problem was not previously observed.
Creating channels via button returns: "createChannel returned 'false'"
I don't know what is wrong. Do I need to include a special property in the payload of my message to make it work maybe?
I had exactly the same problem - also running Android 7 on this device so seems that is responsible. Spent far too much time on this!