从Firebase收到通知时如何打开其他活动 [英] How do I open different activities when receiving notification from Firebase

查看:46
本文介绍了从Firebase收到通知时如何打开其他活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,有不同的类别,一个主页(MainActivity),评论活动和聊天活动等.当我收到来自评论,聊天或主页的通知时,它仍会打开主要活动.我想要的是,如果我收到有关聊天"的通知,则它应打开聊天活动,如果收到评论,则应打开评论活动,依此类推...请帮助谢谢.

In my app there are different categories, a main page(MainActivity), comments activities and Chat activity etc. When i receive a notification, either from comments, Chat or main page, it still opens main activity. What I want is if I receive a notification regarding Chat it should open chat activity and if regarding comments it should open comments activity and so on... Please help thanks.

推荐答案

您的问题的答案是 PendingIntent .您将需要在FCM有效负载中发送通知的类型(聊天,评论等),然后在您的 onMessageReceived()中处理通知,了解通知的类型并使用所需的名称创建PendingIntent活动.当用户点击通知时,Android将启动PendingIntent中指定的活动.请参考 android文档.我希望这会有所帮助.

The answer to your question is PendingIntent. You will need to send in the FCM payload the type of notification (chat, comments etc.,) and then in your onMessageReceived() you process the notification, know the type and create a PendingIntent using the desired activity. When users clicks on the notification, android will launch the activity specified in the PendingIntent. Refer to this android documentation. I hope this helps.

[更新]我更喜欢 Bob的答案,但我从未尝试过

[Update] I like Bob's answer better but I've never tried it myself

这篇关于从Firebase收到通知时如何打开其他活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆