0

In normal case app is alive i received the notification and i display it.

{
    "to" : "xxxx",
     "notification": {
    "body": "Hello",
    "title" : "Hello world notification"
  },
    "data" : {
        "data1" : "dddddd",
    "data2" : "mmm"
    }
}

 <service
            android:name=".notifications.MyFirebaseMessagingService"
            android:directBootAware="true"
            android:exported="false"
            android:enabled="true"
            android:stopWithTask="false"
            >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </service>

Since severals days i search a solution to receive notification FCM when my app is not alive.

I try to FirebaseMessagingService / stopWithTask Create other service to manage FirebaseMessagingService etc.

But i don't found a good way and good practice and technical solution.

Finally it not possible to receive notification when app if not alive?

what is the good way to keep app in background and not really killed app when the user swipe?

(i use API 29)

2 Answers2

0

add this code in your Manifest file OnMessageRecive not call if App is background refer this document

https://firebase.google.com/docs/cloud-messaging/android/topic-messaging

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_stat_ic_notification" />
milan pithadia
  • 840
  • 11
  • 16
  • thanks for your answer, i my case the app is not launch, how to do to the device received the notification and wake up my app ? it is possible ? – Vincedrome Mar 10 '21 at 07:05
0

Well FYI, this method doesn't gets called when the app is in background or killed because The notifications are handled by Device OS when the app is in background or killed.

So if you do not want the notifications to be handled by Device OS and wants this method to be executed even in background and killed state then follow this:

  1. First of all, make FCM service like this by removing all unwanted codes

         <service android:name=".push.MyFirebaseMessagingService">
    
             <intent-filter>
                 <action android:name="com.google.firebase.MESSAGING_EVENT" />
             </intent-filter>
    
         </service>
    
  2. Importantly, Make changes in your fcm json payload like this by removing notification object to make OnReceivedMethod work.

    { "to" : "xxxx", "data" : { "bodyText": "Hello", "titleText" : "Hello world notification", "data1" : "dddddd", "data2" : "mmm", } }

firozsaifi24
  • 41
  • 11
  • Thanks for your answer, i want that Device OS received the notification and display, i try to change the manifest and change the json playload. i specify that the application is not launched. So why the device Os not display still the notification ? my case is it possible ? – Vincedrome Mar 10 '21 at 07:01