Quickstart-android: Google FCM getIntent return null on app is not running

Created on 11 Jun 2016  路  6Comments  路  Source: firebase/quickstart-android

Please help me! I check debug this code extras alway return null when click on new notification, if app is not running, and show good on app is running

    @Override
    public void onNewIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            if (extras.containsKey("local_notification_message")) {
            }
        }
    }

Most helpful comment

Hi,

If your app is just in the background, onNewIntent would be called.

If your app is not running at all, the intent is normally passed through the onCreate, where you should handle it. Can you check this ?

Ben.

All 6 comments

Hi,

If your app is just in the background, onNewIntent would be called.

If your app is not running at all, the intent is normally passed through the onCreate, where you should handle it. Can you check this ?

Ben.

@hungud I believe @Ben834 has offered the correct solution here so I will close this issue. Please re-open if checking in onCreate does not work for you.

Im having the same problem , the intent doesnt hold any data, both on onCreateand onNewIntent

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.

here is concepts: There are two types of messages in FCM:

display-messages: These messages only work when your app is in foreground.

data-messages: 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.

for handling data-messages your notification should have click_action = "YOUR_ACTION" field.

My message will like this:

{
"data": {
"body": "here is body",
"title": "Title",
"click_action": "YOUR_ACTION"
},
"to": "ffEseX6vwcM:APA91bF8m7wOF MY FCM ID 07j1aPUb"
}
The Activity will display the message that menifest file will like this:

android:name=".NotificationActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Dialog"
android:windowSoftInputMode="stateHidden" >

        <intent-filter>
            <action android:name="YOUR_ACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

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

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()));
}
}
Unfortunately in my NotificationActivity i am getting bellow message:

google.sent_time: 1471631793774

from: 50711789666

google.message_id 0:1471631793776823%098e508d098e508d

collapse_key: com.myapp.package_name

But where is my expected notification data?

Here is my system configuration:

Android Studio Version: 2.1.3

Firebase Version: com.google.firebase:firebase-auth:9.0.1

Google Play service version : com.google.android.gms:play-services:9.2.1

Unfortunately in my NotificationActivity i am getting bellow message:

google.sent_time: 1471631793774

from: 50711789666

google.message_id 0:1471631793776823%098e508d098e508d

collapse_key: com.myapp.package_name

finally, i solved my problem. Please visit this answer
Firebase Notification Problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ksachdeva11 picture ksachdeva11  路  4Comments

shivamsriva31093 picture shivamsriva31093  路  3Comments

rahuldevanavar91 picture rahuldevanavar91  路  5Comments

rosariopfernandes picture rosariopfernandes  路  6Comments

smoi picture smoi  路  5Comments