I am using @krystiansliwa solution but it's not a proper fix. I am using the latest version and so does react native firebase have a fix for it or not?
@rbsl-yasmin I have no idea what you're on about 馃槃 this is why we have an issue template. #155 that you linked is also v2 - v4 is the latest?
Please fill out the issue template correctly with a new issue or if there are also similar issues like this so please try not to duplicate if you can.
I ran into an issue integrating notifications while using react-native-splash-screen. Removing the splash screen library allowed this one to function properly.
@Maximell to get this working with a splash you should be able to move your intent filters to your splash screen activity if necessary on your AndroidManifest.
@Maximell were you able to solve this issue.
@Salakar @selvesandev @Maximell @rbsl-yasmin
Adding intent-filter to MainActivity and click-action to notification JSON did the trick for me.
<intent-filter>
<action android:name=".MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
{
"to":"ID",
"notification" : {
"click_action": ".MainActivity",
"body": "Message Body",
"title": "Msg Title",
"sound": "default"
},
"data": {
"type": 1,
"body": "Message Body",
"title" : "Call Status"
}
}
My manifest.xml looks like this
<application
tools:replace="android:allowBackup"
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:launchMode="singleTop"
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:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name=".MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Hope this helps
I am using splash screen with webview and I am also getting the same problem getInitialNotification events are not triggered
this is my manifest file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
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:configChanges="orientation|keyboardHidden|screenSize"
android:allowEmbedded="true"
android:hardwareAccelerated="true">
<intent-filter>
<action android:name=".MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".Service.MyFirebaseIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".Service.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
I solved this with the following files
NotificationListeners.js
import firebase from 'react-native-firebase';
import { ts } from './FirebaseHelpers';
// https://rnfirebase.io/docs/v5.x.x/notifications/introduction
export const notificationDisplayedListener = () =>
// app in foreground
firebase.notifications().onNotificationDisplayed(notification => {
console.log('onNotificationDisplayed');
console.log(notification);
});
export const notificationListener = () =>
// app in foreground
firebase.notifications().onNotification(notification => {
console.log('notificationListener');
console.log(notification);
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
show_in_background: true,
})
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.android.setChannelId('General')
.android.setSmallIcon('@mipmap/ic_notification')
.android.setColor('#F2C94C')
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(localNotification);
console.log('displayed');
firebase.notifications().removeDeliveredNotification(localNotification.notificationId);
});
export const notificationOpenedListener = () =>
// app in background
firebase.notifications().onNotificationOpened(notificationOpen => {
console.log('notificationOpenedListener');
console.log(notificationOpen);
const { action, notification } = notificationOpen;
firebase.notifications().removeDeliveredNotification(notification.notificationId);
console.log('OPEN:', notification);
});
export const notificationTokenListener = userId =>
// listens for changes to the user's notification token and updates database upon change
firebase.messaging().onTokenRefresh(notificationToken => {
console.log('notificationTokenListener');
console.log(notificationToken);
return firebase
.firestore()
.collection('users')
.doc(userId)
.update({ pushToken: notificationToken, updatedAt: ts })
.then(ref => {
console.log('savePushToken success');
})
.catch(e => {
console.error(e);
});
});
SplashActivity.java
package com.daviswhitehead.shayr.android;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
// Pass along FCM messages/notifications etc.
Bundle extras = getIntent().getExtras();
if (extras != null) {
intent.putExtras(extras);
}
startActivity(intent);
finish();
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.daviswhitehead.shayr.android"
xmlns:tools="http://schemas.android.com/tools" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<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"
tools:replace="android:label">
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:label="@string/APP_NAME"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/APP_NAME"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:exported="true"
android:launchMode="singleTask" >
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<!-- NOTIFICATION DEFAULTS -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
See README(https://goo.gl/l4GJaQ) for more. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_notification" />
<!-- android:resource="@drawable/ic_notification" /> -->
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. See README(https://goo.gl/6BKBk7) for more. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/yellow" />
<!-- SHARE ACTIVITY -->
<activity
android:noHistory="true"
android:name=".share.ShareActivity"
android:configChanges="orientation"
android:label="@string/TITLE_ACTIVITY_SHARE"
android:screenOrientation="portrait"
android:theme="@style/Theme.Share.Transparent" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
// for sharing links include
<data android:mimeType="text/plain" />
// for sharing photos include
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<!-- FABRIC -->
<meta-data
android:name="io.fabric.ApiKey"
android:value="c12e5c4bb8cd8ca855a8ada44fa3fde413006659" />
<!-- REACT-NATIVE-FIREBASE NOTIFICATIONS -->
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<!-- SCHEDULED NOTIFICATIONS -->
<receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
<receiver android:enabled="true" android:exported="true" android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
Most helpful comment
@Salakar @selvesandev @Maximell @rbsl-yasmin
Adding
intent-filtertoMainActivityandclick-actionto notification JSON did the trick for me.My manifest.xml looks like this
Hope this helps