0

This is my payload. When I send it I am able to receive notification, but click_action is getting ignored and it launches the launcher activity. But when I put "click_action" in notification block it is working. Why android block is getting ignored?

{
"to": "my tocken",
"data": {
    "url": "dfhdfh",
    "action": "fhdfg",

},
"notification": {
    "title": "dfgsdfg",
    "body": "dfgdg"
},
"android": {
    "notification": {
        "click_action": "NOTIFICATION_ACTIVITY"
    }
}

}

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vishal Gaur
  • 658
  • 6
  • 18
  • 1
    There are two message protocols: [Legacy](https://firebase.google.com/docs/cloud-messaging/http-server-ref#send-downstream) and [HTTP v1](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages). It looks like you are trying to use elements from both. You have what looks like a legacy message, but legacy protocol does not have "android" block. – Bob Snyder May 21 '19 at 19:02

2 Answers2

0

There is three type of message in firebase push notifications

  • Notification Message
  • Data Message
  • Messages with both notification and data payload

And access level of these type in android side is bit different from each other therefore you need to understand that before implementing push notification in the both back end side and android side

you can get better understanding by reading this blog https://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

Dulanga
  • 921
  • 11
  • 23
0

I think you should send only data message and then in onMessageReceived of FirebaseMessagingService, you can generate custom notification and retrieve data from RemoteMessage object.

public class CloudMessagingService extends FirebaseMessagingService {    
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage){
        //Extract data from remote message
        //trigger notification
    }
 }

Under the data object you can have multiple key-value pairs for notification and all the other actions you want to perform.

Also declare CloudMessagingService as a service in AndroidManifest.xml with intent-filter as

<service android:name=".fcm.CloudMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
Sushant Somani
  • 1,450
  • 3
  • 13
  • 31