安卓上的颤振应用程序在单击通知时不会打开应用程序



按照 https://pub.dev/packages/firebase_messaging 的说明,我已经实现了FCM。虽然我已经设置了click_action: FLUTTER_NOTIFICATION_CLICK,但当我单击通知托盘项目时,它无法打开应用程序。颤振应用从云函数接收的数据如下。如何至少在单击通知时打开应用程序?

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

我还创建了通知通道,并且已正确配置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);
},
);

相关内容

  • 没有找到相关文章

最新更新