wyx
wyx

Reputation: 3534

Receive notification by FCM when exit the app

It is my first time to use FCM.I use Android device.

When I exit my app which does not run in the background ,I send some notification to my device.When I reopen my app,I can`t get any notification which I send before.

So is it normal for FCM? If it`s normal,how can I know my message real reach the device? If it is not normal,what should I do?

I use the FCM Sample which I download from official github.I can get notification successfully when app is active or run in the background.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.firebase.quickstart.fcm">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name="com.google.firebase.quickstart.fcm.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- [START firebase_service] -->
        <service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <!-- [END firebase_service] -->
        <!-- [START firebase_iid_service] -->
        <service android:name=".MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        <!-- [END firebase_iid_service] -->

        <service android:name=".RegistrationIntentService" />
    </application>

</manifest>

This is what I send

{
  "notification" : {
      "body" : "fsdf19",
      "title" : "fsdfsd"
    },
  "data":{
    "body":"adfadffdasdfafasdfasf",
    "title":"asdfadfaf"
  }

  "priority":"high",
  "registration_ids" : ["dVWKLIPn7J4:APA91bFv1U5IG8-YOrjNsWIDJsj4sCACGOi-f6FRv4ebr-fhQIT1wL6yzyVoK3rMIAfXAYpj2qkumvqf1pqwtIcv18MDdFtt_RCge-t0acN15htbEd_EAHmU41lGHaVAbq_g_58sDewy"]
}

Upvotes: 1

Views: 3180

Answers (2)

Abhishek
Abhishek

Reputation: 1028

Messages which are sent through the Firebase console are visible only when app is in foreground.

To handle messages when app is in background, you have to send data messages.

Refer this link: https://stackoverflow.com/a/37845174/3152278

enter image description here

Upvotes: 1

Arthur Thompson
Arthur Thompson

Reputation: 9225

FCM will not receive messages when your app is closed/stopped. In order for your service to be started and handle the message your app must be either running or in the background.

Upvotes: 0

Related Questions