Het*_*tal 12 android dart flutter
我正在尝试为 Flutter 应用程序实现 firebase 推送通知。
但它在状态栏中显示为一个图标。我怎样才能让它弹出?
我想在收到通知时在屏幕上弹出。
这是我的代码的样子:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
luk*_*uke 15
如果FCM HTTP API 中未指定,所有通知都将发送到其他通道。杂项频道具有默认的重要性级别,只有声音但不会在屏幕上弹出。android_channel_id
要使通知在屏幕上弹出,您需要创建一个重要性为 max/high 的通知通道。有关如何创建通知通道的详细步骤,您可以参考FlutterFire 的通知通道文档。
创建通知通道后,您可以将通道 ID(例如:high_importance_channel)添加到 FCM HTTP API 请求正文中,当您的应用程序处于后台时,发送到此通道的通知应该开始在屏幕上弹出。
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4371 次 |
| 最近记录: |