Dip*_*eja 6 firebase flutter firebase-cloud-messaging
我的问题似乎类似于这个firebase_messaging onResume 和 onLaunch 不起作用但是我认为该解决方案对我不起作用,因为我已经在尝试访问数据属性中的字段。
当应用程序运行并且该部分工作正常时,我目前正在向用户显示推送通知。但是,我还想在应用程序处于后台时显示通知,并且当用户单击它时,应该会收到一条警报消息。
在 onResume 方法中,如果我这样做,它会起作用,当我打开通知时,我会看到控制台上打印的消息以及警报消息
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
Alert(context: context, title: 'Hi User!').show();
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试访问标题中的数据属性,我会看到控制台上打印的消息,但我现在看不到任何警报
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
Alert(context: context, title: message['data']['user']['name']).show();
}
Run Code Online (Sandbox Code Playgroud)
当应用程序在onMessage
属性中运行时,同一段代码有效,但是对于两者onLaunch
,onResume
我都看到了上述行为。以下是来自控制台的日志
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}}
Run Code Online (Sandbox Code Playgroud)
click_action: 'FLUTTER_NOTIFICATION_CLICK'
您必须在通知负载中添加新的键值 。喜欢关注
{
notification: {
title: 'Title',
body: 'Body',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
}
Run Code Online (Sandbox Code Playgroud)
还在活动标记内的清单文件中添加以下代码
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4006 次 |
最近记录: |