Dieguinho
Dieguinho

Reputation: 788

Firebase click_action not working

I've got a problem with FCM, as documented by the Firebase Team:

click_action: Indicates the action associated with a user click on the notification. When this is set, an activity with a matching intent filter is launched when user clicks the notification.

I know its been discussed, but according to my understanding this should be possible from the firebase console by what I understand from the documentation. It doesn't say its for data-messages it clearly says its a field for notification-messages, and as I understand, these are the ones that the Firebase Console send.

Can anyone clarify this. Thanks!!

Upvotes: 2

Views: 6761

Answers (3)

Lakshmanan
Lakshmanan

Reputation: 1669

You can use following snippet of Rest Service to send push Message from RestClient (Postman)

Method : POST 
URL: https://fcm.googleapis.com/fcm/send
Header:
Authorization : key=<FCM SERVER LEGACY KEY>
Content-Type: application/json

Body: 

{

        "notification": {
            "title": "Firebase notification",
            "message": "I am firebase notification. you can customise me. enjoy",
            "click_action": "OPEN_ACTIVITY",
            "sound":"default",

        }
    ,
    "to": "<Your device FCM Token - Getting it from the FirebaseInstanceIdService>"
}

At your Manifest file - Include the Intent filter to match the Click_action value: Ex:

<activity
            android:name=".ui.NotificationActivity"
            >

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

Upvotes: 1

Arthur Thompson
Arthur Thompson

Reputation: 9225

click_action is not available thorough the Firebase console at this time.

You are correct in saying that the console send notification messages however it does not allow you to set the click_action field of the notification message. To use click_action you have to send a notification message using the REST API where all the notification message fields are available.

Note that the custom data that is added via the console becomes key/value pairs in the data payload that will accompany the notification message. Example structure:

{
  "to": <topic>,
  "notification": {
    <notification payload>
  },
  "data": {
    <data payload, console custom data key/value pairs go here>
  }
}

So the click_action is part of the notification payload but you must use the REST API to use it at this point. I understand that this is not clear, I will look into possible doc updates to make this clearer.

Upvotes: 3

crysxd
crysxd

Reputation: 3490

The console seems to not support click_action so far. You either have to use the API to trigger the notification or try to pass the click_action parameter via the custom data fields in the advanced section when composing a notification in Firebase Console (I have not tried this so far, but might work).

Upvotes: 3

Related Questions