Cannot get Notification content if app is in background
See original GitHub issueI can recevie the notification from firebase remotly. If the app is runing in foreground,
I receive the notification content normally, but if the app is in background, I receive the notification and when click on notification, the app opens up, but the method: onNotification
is not called for some reason. I have seen a lot of issues based on this problem, but no success.
here is my AndroidManifest.xml
`<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/icon" android:allowBackup="false" android:theme="@style/AppTheme">
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/icon"/>
<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>
<activity
android:name=".SplashActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:theme="@style/SplashTheme"
android:label="@string/app_name"
android:launchMode="singleTop"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:exported="true">
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>`
and here is my App.js
import PushNotification from 'react-native-push-notification';
class App extends Component {
state = { color: 'red' };
constructor() {
super();
PushNotification.configure({
onRegister: ({ token }) => this.register(token),
onNotification: notif => this.receivePushNotification(notif),
senderID: 'XXXX',
requestPermissions: true
});
}
componentDidMount = () => {
SplashScreen.hide();
AppState.addEventListener('change', this.handleAppStateChange);
};
handleAppStateChange = appState => {
if (appState === 'active') {
PushNotification.popInitialNotification(notification => {
console.warn('notification', notification); //notification is null
});
}
};
register = token => {
console.warn('token', token);
};
receivePushNotification = notification => {
console.warn('notification', notification); //only enter here if I receive the notification in foreground mode, if I receive in background and click on notification, this method is not being called
};
}
If anybody knows how to solve this, or know if FCM is supported by this library I would greatly appreciate it.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Android Notifications Not Showing Up? 10 Fixes You Can Try
Not seeing notifications show up on your Android phone? Try these fixes to get Android notifications working again.
Read more >Issue with receiving notifications when app is in background
For notification messages, onMessageReceived is only called if your app is in the foreground. Otherwise the the message will be delivered to the ......
Read more >Pushing Background Updates to Your App - Apple Developer
A background notification is a remote notification that doesn't display an alert, play a sound, or badge your app's icon. It wakes your...
Read more >Notifications Overview | Android Developers
A notification is required when your app is running a "foreground service"—a Service running in the background that's long living and noticeable to...
Read more >Data & Background Notifications - OneSignal Documentation
. Background/Data Notification Limitations ... If you force close the app, it cannot receive background/data notifications. iOS Apps are force closed when you ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you @hoangpm2
@uzairkhan01 I am using react-native-firebase. https://rnfirebase.io/