3

i did not any receive fcm when my app is closed in foreground and open state i received but in background state not working i think all my code is ok but not receive

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      package="com.sample_project">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
  android:usesCleartextTraffic="true"
  tools:targetApi="28"
  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"
>


    <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id"/>

    <meta-data android:name="com.google.firebase.messaging.default_notification_icon"
               android:resource="@mipmap/ic_launcher"/>

    <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>

    <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="com.infuy.toshisanapp" />
        </intent-filter>
    </receiver>


    <service android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionsService"/>

    <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.RNFirebaseBackgroundMessagingService" />

    <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=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize"
    android:screenOrientation="portrait"
    android:launchMode="singleTop"

    >
    <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" />
</application>

and in index file i put this

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import {firebaseBackgroundMessage} from "./res/Global/FcmManager";
AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => firebaseBackgroundMessage); 

and in firebaseBackgroundMessage i have this code

export async function firebaseBackgroundMessage(message: RemoteMessage) {
console.log("firebaseBackgroundMessage::::::::::::::::::::::::::::::");
let notif=message['data'];
console.log(JSON.stringify(message));
const groupNotificationId = 'test';
const body = 'Chats list';
const smallIcon = 'ic_launcher';
const channel = new firebase.notifications.Android.Channel(
"reminder", // channelId
              "Reminders Channel", // channel name
              firebase.notifications.Android.Importance.High // channel importance
            ).setDescription("Used for getting reminder notification"); // channel description
            firebase.notifications().android.createChannel(channel);

            const groupNotification = new firebase.notifications.Notification()
              .setNotificationId(groupNotificationId)
              .setSubtitle(body)
              .setTitle(Data.data.title)
              .setBody(Data.data.text)
            groupNotification
              .android.setGroup(groupNotificationId)
              .android.setGroupSummary(true)
              .android.setChannelId('reminder')
              .android.setSmallIcon(smallIcon)
              .android.setAutoCancel(true);
            firebase.notifications().displayNotification(groupNotification);
return Promise.resolve();

}

plz help me i did test more a lot of sample code and permission but not working i am tired

and sample of package.json

"react": "16.9.0",
"react-native": "0.61.5",
"react-native-firebase": "^5.5.6",
"react-navigation": "^4.1.0",
"react-navigation-stack": "^2.1.0",
Samira Gheibipour
  • 380
  • 1
  • 3
  • 15
  • Which one is your push notification provider? Cloud Messaging? Amazon SNS? Are you able to set priority to HIGH on the provider? For Google Cloud Messaging try [this link](https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message) – Filipe Merker Jul 29 '20 at 12:37
  • Hi Samira, How did you solved this issue? I'm facing the same issue now. – mr.volatile May 27 '22 at 06:48

2 Answers2

1

You should created receiver which handles on device boot event and then create a background service which connects to firebase. In this case even if app terminated by user, service will work.

boot receiver sample:

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // do your coed

    }
}
Farhad
  • 1,873
  • 17
  • 28
  • how in react native? i put receive in manifest. i think it is in java android(native) but in react native is different – Samira Gheibipour Jul 22 '20 at 08:30
  • I think you can handle whole part of Notification in Java part beside your react native, there is lots of tutorial for this. – Farhad Jul 22 '20 at 08:59
0

Which module you are using for push Notification? Push Notification is working on iOS?

Yashvant
  • 36
  • 2