gpt4 book ai didi

android - 单击通知时,Android 上的 Flutter 应用程序不会打开应用程序

转载 作者:行者123 更新时间:2023-11-30 04:55:20 25 4
gpt4 key购买 nike

按照 https://pub.dev/packages/firebase_messaging 上的说明进行操作,我已经实现了 FCM。虽然我设置了 click_action: FLUTTER_NOTIFICATION_CLICK,但当我点击通知托盘项目时,它并没有打开应用程序。 flutter app从云函数接收到的数据如下。我至少要如何在点击通知时打开应用程序?

onMessage: {notification: {title: pi, body: text message.}, 
data: {USER_NAME: pi, click_action: FLUTTER_NOTIFICATION_CLICK, }}

云函数负载

 const payload = {
notification: {
title: sender,
body: content,
clickAction: 'ChatActivity',
},
data: {
"click_action": 'FLUTTER_NOTIFICATION_CLICK',
"USER_NAME": sender,
}
};

我还创建了通知 channel 并且 AndroidManifest 已正确配置。

private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.app_name);
String description = getString(R.string.notification_channel_description);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(getString(R.string.default_notification_channel_id), name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}

最佳答案

我已将点击操作放入通知 json,它对我有用。

notification: {
title: sender,
body: content,
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}

只有 onResumeonLaunch 回调需要点击操作,所以一定要按照 pub.dev 文档中的说明实现它:

 _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);
},
);

关于android - 单击通知时,Android 上的 Flutter 应用程序不会打开应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59283928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com