-
Notifications
You must be signed in to change notification settings - Fork 766
Foreground Notifications are not working #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm experiencing the same issue for Foreground Notification on Android. It works on IOS, have you managed to fix it ? |
Oh hey, I figured it out, you have to write your own MyFirebaseMessaging.java in Android Studio, and add it to Manifest. https://gist.github.com/jirawatee/85d4b46a89b9ae821b63c31f5d5189de, have a look at it |
Foreground notification not working for Android. I have checked the device logs & confirm message is received by app but event is not getting fire in RN. |
@dangkhoa2708 can you give one sample on how exactly you had resolved this issue ? |
}` |
Hi @dangkhoa2708 , |
I got FCM token using react-native-firebase v6. You can consult their site https://invertase.io/oss/react-native-firebase/v6/messaging/quick-start. It got one error on IOS, so I did a trick with NativeModule as suggested on their GitHub issues. You might come across it, and I believe you can find it too. Or else, come back here lol :D |
I added this code to subscribe to firebase service: |
@xoapit |
I added this to my `/android/app/src/main/AndroidManifest.xml' and it works. |
Hi @dangkhoa2708, I added the class you made and it correctly displays notifications on foreground, thank you!! But, after I added it to the manifest, I can't receive anymore the messages on the listener in the react native code, and I still need that to manage "silent" firebase notifications. How can I fix this? |
Nevermind, fixed it. If anyone needs it, I just had to modify the class extending
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
The issue has been closed for inactivity. |
I still have the same issue on Android. For RN 0.61.5 |
from ./node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java change this code
to
|
Being a newbie, it took me quite a while to understand the different suggestions mentioned by the experts above. Here is a summary of how I got it to work. A big thank you to all the experts above. A. Edit the following file. Obviously, your changes will be lost if you reinstall/upgrade the React-Native-Notifications package. You might need to redo this step if the newly installed version still has this problem. A.1 Remove the following: @Override
public void onReceived() throws InvalidNotificationException {
if (!mAppLifecycleFacade.isAppVisible()) {
postNotification(null);
}
notifyReceivedToJS();
} A.2 Add the following. @Override
public void onReceived() throws InvalidNotificationException {
postNotification(null);
notifyReceivedToJS();
} B. Update the following file <manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MyProject">
<uses-permission android:name="android.permission.INTERNET" />
<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="com.facebook.react.devsupport.DevSettingsActivity" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
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>
<!-- You need to add the following <Service> section -->
<service
android:name="com.wix.reactnativenotifications.fcm.FcmInstanceIdListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest> This worked for me on: |
This solution works well, thanks for sharing! |
@Bilal-Abdeen This was incredibly helpful! I followed everything in your comment and I am good now! |
Change made in accordance to: wix#525 (comment)
@Bilal-Abdeen Thanks for sharing, this also worked for me! |
The solution works well but if some people don't want to edit the source code of the lib to have an easier maintainability, there is another solution. As shown in the previous solution, the problem is not that the notification is not detected but that it is not posted so it doesn't appear in the Notification Bar. But the library still notify the JS code that a notification arrived. You can get this notification using Here is my solution:
Ios foreground notification works for me so that's why I only do it for the Android part but you can use it for both and adapt it |
To fix issue wix#525 (wix#525), I did 2 changes below. ``` @OverRide public void onReceived() throws InvalidNotificationException { // 1. removed the following if/else statement // if (!mAppLifecycleFacade.isAppVisible()) { // postNotification(null); // notifyReceivedBackgroundToJS(); // } else { // notifyReceivedToJS(); // } // 2. added the following 2 statements, instead of the if/else statement above postNotification(null); notifyReceivedToJS(); } ```
@mslipenchuk267 @wixmobile, It seems that this issue still exists in version
|
This seems to be the fix (still on react-native v0.67.5) for me but I don't know how to keep updating this file as I run through a CI/CD pipeline. Any thoughts? |
@ilight I have decided to use https://rnfirebase.io/messaging/usage and https://github.com/invertase/notifee, instead of this library. |
@ilight to keep the changes every time after yarn install, look at https://github.com/ds300/patch-package |
Yes we eventually did our own patch for this which seems to be working |
In my case, in turned out that there were 2 packages (react-native-moengage & react-native-notifications) that were using However it seems that only one service will receive push notification and the precedence will take the service that is declared earlier/higher in the |
Unable to receive foreground notifications on Android( didn't test on iOS ) with OS 10.
When app is minimized the notifications are working.
But the events are not being fired even I receive notification on background.
In foreground event is not getting fired and unable to receive notification.
Could anyone please suggest!
The text was updated successfully, but these errors were encountered: