-1

I want add push cloud message in my application. I add in manifect:

<service
        android:name=".firebase.MyFirebaseMessagingService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
</service>

and add MyFirebaseMessagingService class and interface for it. If my application is run, I get message as RemoteMessage in my service. If application is down, push message receiver android and show notification in top part of the screen. I click this push, my application runninig and mainAcrivity have intent extras. Code in mainActivity onCreate:

if (getIntent().getExtras() != null) {
        for (String key : getIntent().getExtras().keySet()) {
            Object value = getIntent().getExtras().get(key);
            Log.d(TAG, "Key: " + key + " Value: " + value);
        }
    }

Logcat output:

Key: google.delivered_priority Value: high
Key: google.sent_time Value: 1574665753356
Key: google.ttl Value: 2419200
Key: google.original_priority Value: high
Key: from Value: 69200725691
Key: google.message_id Value: 0:1574665753390474%7139185571391855
Key: collapse_key Value: ru.ittest.freezio_senser

Why I receiver no RemoteMessage? How can I get RemoteMessage use this keys?

2 Answers2

0
{
"notification":{"title":"YOUR TITLE","body":"YOUR BODY"},
 "to": "your device token",
 "data":{
 "project_type": "Remodel",
 "name": "Start 45 "
     }
 }

Your notification response look like this . if your notification response contain this notification tag"notification":{"title":"YOUR TITLE","body":"YOUR BODY"}, then if app running then onMessageReceived method will call or if app is killed then onMessageReceived method won't call . To solve this problem you have to "notification":{"title":"YOUR TITLE","body":"YOUR BODY"}, from notification response.

And you want to open specific activity on onclick of notification. Add this codes in activity tag in manifest <intent-filter> <action android:name="NotificationActivity" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>

And replace intent in Notification code in onMessageReceived val intent = Intent("NotificationActivity")

Pass that this intent in pendingIntent val pendingIntent = PendingIntent.getActivity(this,101,intent,PendingIntent.FLAG_UPDATE_CURRENT)

Rahul sharma
  • 1,492
  • 12
  • 26
  • I ask no it. In documentation - https://firebase.google.com/docs/cloud-messaging/android/receive I can see: "Notification: system tray Data: in extras of the intent." But really in extras is: Key: google.delivered_priority Value: high Key: google.sent_time Value: 1574665753356 Key: google.ttl Value: 2419200 Key: google.original_priority Value: high Key: from Value: 69200725691 Key: google.message_id Value: 0:1574665753390474%7139185571391855 Key: collapse_key Value: ru.ittest.freezio_senser Where is message title, body, image URI? How can I see it use extras? – Prostakov Alexey Nov 25 '19 at 09:20
  • I look - https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase/42279260#42279260. In this post and in google documentation getIntent().getExtras() -> get body key, "//bundle must contain all info sent in "data" field of the notification" . But in really - no contain. – Prostakov Alexey Nov 25 '19 at 13:37
  • that's true. You have dynamically store that data in onMessageReceived method. – Rahul sharma Nov 25 '19 at 13:39
0

I find decide for it problem.

  1. Thanks for Arthur Thompson: "the title body and image is not available when the user taps on the notification. If you want to get that data you will have to add it to the "data" payload of the message you are sending."

  2. Add payload in firebase console: enter image description here

  3. Now info received in MainActivity as:

    Bundle bungle = getIntent().getExtras(); if ( bungle != null) { Object title = bungle.get("title"); .... }