Firebase FCM notifications click_action payload
If your app is in background, Firebase will not trigger onMessageReceived(). Why.....? I have no idea. In this situation, I do not see any point in implementing FirebaseMessagingService.
According to docs, if you want to process background message arrival, you have to send 'click_action' with your message.
But it is not possible if you send message from Firebase console, only via Firebase API.
It means you will have to build your own "console" in order to enable marketing people to use it. So, this makes Firebase console also quite useless!
There is really good, promising, idea behind this new tool, but executed badly.
I suppose we will have to wait for new versions and improvements/fixes!
How to specify sound and click_action in firebase cloud function
Ok, I finally managed to gather bits and pieces here and there to make it work. Don't understand why the docs do not have a clear and direct path to such a common requirement.
exports.sendComNotification = functions.firestore .document('Comunicados/{comID}') .onCreate((snap, context) => { const doc = snap.data(); const msg = doc.title; var message = { notification: { title: 'Comunicado da Diretoria!', body: msg }, data: { title: 'Comunicado', body: msg }, android: { notification: { sound: 'default', click_action: 'FLUTTER_NOTIFICATION_CLICK', }, }, apns: { payload: { aps: { badge: 1, sound: 'default' }, }, }, topic: "Comunicados" };
return admin.messaging().send(message) .then((response) => {
console.log('Successfully sent message:', response); return }) .catch((error) => { console.log('Error sending message:', error); return });
});
How to send Push Notification With Custom Click Action From Firebase Console
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);
Firebase Cloud Messaging click_action format is platform specific?
FCM works based on IDs generated by devices which are different depending on the device, platform, and curl session. So, they would be different for Android, iOS and Web. If you want to send to all platforms, you have to call the method three times (once for each platform) with a different payload or curl session for each. I'm sending to two platforms (iOS and Android) with two different function and calling them at the same time.
Related Topics
Android Tablayout Android Design
Margins of a Linearlayout, Programmatically with Dp
How to Set Different Columns for Rows in Android Gridview
Move Snackbar Above The Bottom Bar
Android Studio Could Not Find Any Version That Matches Com.Android.Support:Appcompat-V7:+
Android Device Monitor "Data" Folder Is Empty
How to Set a Fragment Tag by Code
How to Find Memory Leak Class/Activity in Android
Findbugs Idea - Classnotfoundexception Com.Google.Wireless.Android.Sdk.Stats.Intellijindexingstats
Writing Some Characters Like '<' in an Xml File
How to Change Color of Vector Drawable Path on Button Click
How to Enable Internal App Sharing for Android
Android Device Phone Call Ability
Invalid Heap Address and Fatal Signal 11
Gradle Warning: Variant.Getoutputfile() and Variant.Setoutputfile() Are Deprecated
Android Sdk Install: Java Se Development Kit (Jdk) Not Found