如何将用户重定向到通知页面上的单击 [英] how to redirect users to a page on notification click
问题描述
我正在使用Firebase服务器开发Flutter应用程序和Web.我使用云功能发送通知.我想在用户收到通知并单击它时将用户重定向到特定页面.现在,当我收到通知并单击它时,我的应用程序显示主页".当用户收到通知并单击它时,如何重定向到请求详细信息页面"而不是主页"?
I am working on flutter app and web with firebase server. I send notifications using cloud functions. I want to redirect users to a specific page when they get a notification and click on it. For now, my app shows 'home page' when I get a notification and click on it. How can I redirect to 'request detail page' instead of 'home page' when users get a notification and click on it?
推荐答案
将此内容添加到AndroidManifest文件中
Add this inside AndroidManifest file
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
在通知数据内部,添加click_action和用于导航到特定页面的必需参数
Inside notification data, Add click_action and your required parameter for navigating to a specific page
'data': {
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'product_id': 1,
...
},
当用户单击通知时,这三个事件之一将触发,具体取决于您的应用状态.
When user click on the notification one of these three event will trigger depending on your app state.
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
_showItemDialog(message);
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
_navigateToItemDetail(message);
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
_navigateToItemDetail(message);
},
);
从消息&中检索通知数据导航到所需页面.
Retrive the notification data from message & navigate to your desired page.
这篇关于如何将用户重定向到通知页面上的单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!