Identify if an activity was opened from FCM notification click

前端 未结 3 905
广开言路
广开言路 2021-01-05 02:45

I am using the fcm console to send messages to all of devices that have my app installed, the notifications don\'t have any extra payload only the notification message.

3条回答
  •  心在旅途
    2021-01-05 02:58

    if you want to Start any Activity without extending FireBaseMessaging class then you can set this flags with your FCM data payload.

    So whenever the user clicked on FCM Notification on System Tray.That defined Activity should open.And if you want to get extra bundle data.you can get it using getIntent().getExtras(); method.

        "message":{
         "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
         "notification":{
           "title":"Match update",
           "body":"Arsenal goal in added time, score is now 3-0"
         },
    "android":{
               "ttl":"86400s",
               "notification"{
                 "click_action":"MainActivity.class" // define your activity here
               }
             },
     "payload": {
             "aps": {
               "category": "NEW_MESSAGE_CATEGORY"
             }
           }
         }
    

    Please refer to below link:-

    "sets the appropriate keys to define the result of a user tap on the notification on Android and iOS — click_action, and category, respectively."

提交回复
热议问题