gpt4 book ai didi

android - 如何将按钮添加到 Firebase 消息通知?

转载 作者:行者123 更新时间:2023-12-05 00:19:00 26 4
gpt4 key购买 nike

我是新手,我正在使用 firebase-Messaging 向设备发送通知,我们使用 Web API 向 firebase 发送请求以发送通知,而 firebase 向 android 发送通知。
我想在通知标题和正文下显示两个按钮(接受和拒绝),比如瓦应用通知“标记为已读”选项我想要这样的东西。
我添加的 Android list 文件:

<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
flutter 代码
 final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); 
if(user != null)
{
Navigator.push(context,
MaterialPageRoute(builder: (context) => InitialPage()));

_firebaseMessaging.onTokenRefresh.listen(sendTokenToServer);
_firebaseMessaging.getToken();
// _firebaseMessaging.subscribeToTopic('all');

_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
final notification = message['data'];

},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));


}
web api服务代码
 public class NotificationController : ApiController
{
//api/user
public IHttpActionResult GetUsers()
{

WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
//serverKey - Key from Firebase cloud messaging server
tRequest.Headers.Add(string.Format("Authorization: key={0}", "xxxxxxxxxxxxxxxxxxxxxx"));
//Sender Id - From firebase project setting
tRequest.Headers.Add(string.Format("Sender: id={0}", "123456"));
tRequest.ContentType = "application/json";
var payload = new
{

to = "wwwwwwwwwwww",
priority = "high",
content_available = true,
notification = new
{
body = "test body",
title = "Test title",
badge = 1,

},
data = new
{
key1 = "value1",
key2 = "value2"
}

};

string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
//result.Response = sResponseFromServer;
}
}
}
}

return Ok("test service");



}

}

最佳答案

用于推送通知的 Firebase 云消息传递服务不提供将操作按钮添加到通知布局的选项。因此,为了在通知中添加操作按钮,我们现在唯一的方法是在原生中创建通知并将其与 Flutter 集成。
查看this中等职位

关于android - 如何将按钮添加到 Firebase 消息通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64968731/

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