Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

android - Google FCM getIntent not returning expected data when app is in background state

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.

Based on 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 manifest file will like this:

<activity
            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 below 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

Here are some related links:

Thanks in advance. Sorry for bad English.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...