I am trying to open a particular activity when the user clicks the notification when the app is in the background. From the Docs, I have got that click_action has to be added in the payload and an intent filter in the App to handle it. But, how to add click_action in the Firebase Notifications via Firebase Console? I am open to any other Work Around too. Thanks in Advance.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
This falls into workaround category, containing some extra information too:
Since the notifications are handled differently depending on the state of the app (foreground/background/not launched) I've seen the best way to implement a helper class where the selected activity is launched based on the custom data sent in the notification message.
This way you do not need the click_action or intent filter specific to it. Also you write the code just once and can reasonably easily start any activity.
So the minimum custom data would look something like this:
And the code for handling it:
That is the code for the last two cases, startSelectedActivity would be called also from onMessageReceived (first case).
The limitation is that all the data in the intent extras are strings, so you may need to handle that somehow in the activity itself. Also, this is simplified, you probably don't what to change the Activity/View on an app that is on the foreground without warning your user.
I'm looking this Firebase is , development from google cloud messaging push notification fundamental so we can use the gcm tutorial,function and implementation in firebase , i using funtion of gcm push notification function to solve this click_action problem i use gcm function **
** try this save url click_action in variable url this is in server-worker.js
Well this is clear from firebase docs that your
onMessageReceived
will not work when app is in background.When your app is in background and click on your notification your default launcher will be launched. To launch your desired activity you need to specify
click_action
in your notification payload.And in your
android.manifest
fileAdd the following code where you registered your activity
Update:
So just to verify, it is not currently possible to set the
click_action
parameter via the Firebase Console.So I've been trying to do this in the Firebase Notifications Console with no luck. Since I can't seem to find anywhere to place the
click_action
value in the console, what I mainly did to test this out is to add a custom key/value pair in the Notification (Advance Options > Custom Data):then tried calling RemoteMessage.getNotification().getClickAction() in
onMessageReceived()
to see if it was retrieving the correct value, but it always returnsnull
. So next I tried calling RemoteMessage.getData().get(< specified_key >) and was able to retrieve the value I added.NOTE: I am not entirely sure if that is okay to be used as a workaround, or if it's against best practice. I would suggest using your own app server but your post is specific to the Firebase Console.
The way the client app and the notification behaves still depends on how you program it. With that said, I think you can use the above as a workaround, using the value retrieved from the
getData()
, then having the Notification call this or that. Hope this helps somehow. Cheers! :DIf 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!
As far as I can tell, at this point it is not possible to set click_action in the console.
While not a strict answer to how to get the click_action set in the console, you can use curl as an alternative:
This is an easy way to test click_action mapping. It requires an intent filter like the one specified in the FCM docs:
This also makes use of topics to set the audience. In order for this to work you will need to subscribe to a topic called "news".
Even though it takes several hours to see a newly-created topic in the console, you may still send messages to it through the FCM apis.
Also, keep in mind, this will only work if the app is in the background. If it is in the foreground you will need to implement an extension of FirebaseMessagingService. In the onMessageReceived method, you will need to manually navigate to your click_action target:
As I said, at this time I cannot find a way to access notification payload properties through the console, but I thought this work around might be helpful.