gpt4 book ai didi

firebase - Flutter - 如何使用 FCM onResume 和 onLaunch 方法?

转载 作者:行者123 更新时间:2023-12-03 13:30:11 29 4
gpt4 key购买 nike

我的问题似乎与此类似 firebase_messaging onResume and onLaunch not working但是我认为该解决方案对我不起作用,因为我已经在尝试访问数据属性中的字段。当应用程序运行并且该部分工作正常时,我目前正在向用户显示推送通知。但是,我还想在应用程序处于后台时显示通知,并且当用户单击它时,应该会收到一条警报消息。在 onResume 方法中,如果我这样做,它会起作用,当我打开通知时,我会看到控制台上打印的消息以及警报消息

onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
Alert(context: context, title: 'Hi User!').show();
}

但是,如果我尝试访问标题中的数据属性,我会看到控制台上打印的消息,但我现在看不到任何警报
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
Alert(context: context, title: message['data']['user']['name']).show();
}

当应用程序在 onMessage 中运行时,同一段代码有效然而,两者的属性 onLaunchonResume我看到了上述行为。以下是来自控制台的日志
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (light greylist, reflection) 
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (light greylist, reflection)
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->size()I (light greylist, reflection)
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->get(I)I (light greylist, reflection)
W/awesome_projec(13005): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (light greylist, reflection)
E/FlutterFcmService(13005): Fatal: failed to find callback
W/FirebaseMessaging(13005): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
E/FlutterFcmService(13005): Fatal: failed to find callback
I/flutter (13005): onResume: {notification: {}, data: {collapse_key: com.example.awesome_project, google.original_priority: high, google.sent_time: 15751462256, google.delivered_priority: high, google.ttl: 2419200, from: 554610817622, location: {"latitude":24.6351,"longitude":70.2764}, user: {"phoneNumber":"1274545332","name":"Bobby94"}, google.message_id: 0:157514622564xxx}}

最佳答案

您必须添加新的键值 click_action: 'FLUTTER_NOTIFICATION_CLICK'在通知负载中。喜欢以下

{
notification: {
title: 'Title',
body: 'Body',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
}

还在事件标签内的 list 文件上添加以下代码
  <intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

关于firebase - Flutter - 如何使用 FCM onResume 和 onLaunch 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59120276/

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