Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 256
Alireza Noorali Avatar asked Oct 17 '22 09:10

Alireza Noorali


1 Answers

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);
like image 113
Oussema Aroua Avatar answered Oct 21 '22 08:10

Oussema Aroua