1

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"]
}
wyx
  • 3,334
  • 6
  • 24
  • 44
  • 1
    Please provide your implementation/code of your manifest and your FCM integration – gaara87 Aug 03 '16 at 03:07
  • I have edited again.Thanks your prompt.@gaara87 – wyx Aug 03 '16 at 03:35
  • I think only data messages can be received by the .MyFirebaseMessagingService when it is in the background. If not, the notifications will be displayed to the notification bar. try removing the "notification" part of the push message if you want your app to handle the notification always. – jonDoe Aug 03 '16 at 03:46
  • That seems to be the sample manifest. Also, did you setup your google-services.json file correctly? – gaara87 Aug 03 '16 at 03:48
  • Sure,I have said that it`s successful get the notification when the app is active.@gaara87 – wyx Aug 03 '16 at 03:55

2 Answers2

1

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

Community
  • 1
  • 1
Abhishek
  • 968
  • 10
  • 16
  • 1
    What I want to ask is when app is not in foreground or background ,OK?It is when I close my app completely,can I receive my notification after I reopen it ? – wyx Aug 05 '16 at 02:28
  • Thanks @Abhishek it helped! – Aashish May 29 '17 at 04:10
0

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.

Arthur Thompson
  • 9,087
  • 4
  • 29
  • 33
  • *FCM will not receive messages when your app is closed/stopped.* I don't think that is true. Do you have a source to back up your claim? – Tim Aug 04 '16 at 07:19
  • As of Android 3.1 applications that are stopped should not be woken via broadcasts. See the "Launch controls on stopped applications" section: https://developer.android.com/about/versions/android-3.1.html – Arthur Thompson Aug 04 '16 at 16:12
  • FCM will not receive messages when your app is closed/stopped.I don't think that is true. When the services of the App were shut down, no FCM will be received. – Mike Yang Jan 20 '17 at 06:38