gpt4 book ai didi

android - Firebase 推送通知未在屏幕上弹出 [Flutter]

转载 作者:行者123 更新时间:2023-12-03 02:39:38 26 4
gpt4 key购买 nike

我正在尝试为 flutter 应用程序实现 Firebase 推送通知。

但它只是在状态栏中显示为一个图标。我怎样才能让它弹出?

enter image description here

我想在收到通知时在屏幕上弹出。

这是我的代码的样子:

 Future<bool> sendNotification(var userToken, String bodyMessage) async {
final data = {
"notification": {
"body": bodyMessage,
"title": "Leave Application",
},
"priority": "high",
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done"
},
"registration_ids": userToken,
};

final headers = {
'content-type': 'application/json',
'Authorization':
'key=<Firebase web key>',
};

final response = await http.post(postUrl,
body: json.encode(data),
encoding: Encoding.getByName('utf-8'),
headers: headers);

if (response.statusCode == 200) {
print(response.statusCode.toString());
print("Working");
return true;
} else {
print(postUrl.toString());
print(response.statusCode.toString());
print("Not Working");
return false;
}
}

最佳答案

所有通知将发送至杂项 channel if android_channel_id FCM HTTP API 中未指定。 杂项 channel 带有默认的重要性级别,只有声音但不会在屏幕上弹出。
要在屏幕上弹出通知,您需要 创建一个重要性为 max/high 的通知 channel .关于如何创建通知 channel 的详细步骤,您可以引用Notification Channel Documentation by FlutterFire .
创建通知 channel 后,您可以将 channel id(例如:high_importance_channel)添加到 FCM HTTP API 请求正文中,当您的应用处于后台时,发送到该 channel 的通知应该开始在屏幕上弹出。

{
"notification": {
"android_channel_id": "high_importance_channel",
"title": "Notification Title",
"body": "Notification body ...",
"sound": "default",
"priority": "high",
"time_to_live": 86400,
"click_action": "FLUTTER_NOTIFICATION_CLICK",
},
"data": {
"post_id": 10000012,
"type": "NEWS",
},
"condition": "'dogs' in topics"
}
1st image
2nd image

关于android - Firebase 推送通知未在屏幕上弹出 [Flutter],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60074209/

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