How to send Push Notification With Custom Click Action From Firebase Console

Alireza Noorali picture Alireza Noorali · Jul 10, 2017 · Viewed 10.1k times · Source

I'm going to send push notification with custom click action to set onClick of notification to open an exact Activity in my project when the app is in foreground or background. In all posts and comments it is written that it is impossible to send notification with custom click action from console, but in "Advanced options" in console, it is possible to set custom data keys and values.

Firebase Console

Why it should be impossible to set click_action key and its value?

If it is possible so tell me what should I do. I mean what is the exact intent-filter code? and what should I set as click_action value?

Assume that I want to open SecondActivity by clicking on notification.

Answer

Oussema Aroua picture Oussema Aroua · Jul 10, 2017

yes you can't send notification like this from the firebase console but this is how it works you need to add intent_filter to the activity at the manifest.xml

<activity android:name=".MyActivity">
    <intent-filter>
        <action android:name="com.mypackage.MyActivty_TARGET" />
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

and put your click_action value as the activity action : com.mypackage.MyActivty_TARGET"

and you read the data from the android like this :

String click_action = remoteMessage.getNotification().getClickAction();
Intent in = new Intent(click_action);