Google FCM getIntent not returning expected data when app is in background state
<p>I am implementing FCM (Firebase messaging Service) in my application. Here all seems ok except when app is in background state i am not able to extract expected notification data.</p>

<p>Based on concepts: There are two types of messages in FCM:</p>

<p><strong>display-messages</strong>: These messages only work when your app is in foreground.</p>

<p><strong>data-messages</strong>: Theses messages work even if your app is in background
When our app is in the background, Android directs notification messages to the system tray.</p>

<p>for handling <strong>data-messages</strong> your notification should have <strong>click_action = "YOUR_ACTION"</strong> field.</p>

<p>My message will like this:</p>

<pre><code>{
 "data": {
  "body": "here is body",
  "title": "Title",
  "click_action": "YOUR_ACTION"
 },
 "to": "ffEseX6vwcM:APA91bF8m7wOF MY FCM ID 07j1aPUb"
}
</code></pre>

<p>The Activity will display the message that manifest file will like this:</p>

<pre><code>&lt;activity
            android:name=".NotificationActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Dialog"
            android:windowSoftInputMode="stateHidden" &gt;

            &lt;intent-filter&gt;
                &lt;action android:name="YOUR_ACTION" /&gt;
                &lt;category android:name="android.intent.category.DEFAULT" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
</code></pre>

<p>After clicking on Notification it will redirect to my <code>NotificationActivity</code> . In my <code>NotificationActivity</code> in <code>onCreate</code> and <code>onNewIntent</code> method i am extracting message using this way:</p>

<pre><code>Bundle bundle=getIntent().getExtras();
        if(bundle!=null) {
            for (String key : bundle.keySet()) {
                Object value = bundle.get(key);
                Log.d("DATA_SENT", String.format("%s %s (%s)", key,
                        value.toString(), value.getClass().getName()));
            }
        }
</code></pre>

<p>Unfortunately in my <code>NotificationActivity</code> i am getting below message:</p>

<p><strong>google.sent_time</strong>: 1471631793774 </p>

<p><strong>from</strong>: 50711789666 </p>

<p><strong>google.message_id</strong> 0:1471631793776823%098e508d098e508d</p>

<p><strong>collapse_key</strong>: com.myapp.package_name</p>

<p>But <strong>where is my expected notification data?</strong></p>

<p>Here is my system configuration:</p>

<p><strong>Android Studio Version</strong>: 2.1.3</p>

<p><strong>Firebase Version</strong>: com.google.firebase:firebase-auth:9.0.1 </p>

<p><strong>Google Play service version</strong> : com.google.android.gms:play-services:9.2.1</p>

<p>Here are some related links:</p>

<ul>
<li><a href="https://github.com/firebase/quickstart-android/issues/4" rel="noreferrer">https://github.com/firebase/quickstart-android/issues/4</a></li>
<li><a href="https://github.com/firebase/quickstart-android/issues/47" rel="noreferrer">https://github.com/firebase/quickstart-android/issues/47</a></li>
<li><a href="https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase">How to handle notification when app in background in Firebase</a></li>
<li><a href="https://stackoverflow.com/questions/37358462/firebase-onmessagereceived-not-called-when-app-in-background">Firebase onMessageReceived not called when app in background</a></li>
<li><a href="https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase">How to handle notification when app in background in Firebase</a></li>
</ul>

<p>Thanks in advance. Sorry for bad English.</p>