gpt4 book ai didi

firebase-cloud-messaging - Firebase FCM 通知添加操作按钮

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

如何添加操作按钮来推送这样的通知:
enter image description here
我试过这个,但它不起作用:

=> https://firebase.googleblog.com/2018/05/web-notifications-api-support-now.html

这是我的通知负载:

array
(
"title" => "FCM Message",
"body" => "This is an FCM Message",
"click_action" => "http://example.com/",
"icon" => "/logo.jpg",
"actions" => array(
0 => array(
'title' => 'Like',
'click_action' => 'http://example.com/?aaa=1',
'icon' => 'icons/heart.png',
),
1 => array(
'title' => 'Unsubscribe',
'click_action' => 'http://example.com/?aaa=2',
'icon' => 'icons/cross.png',
),
),
);

我尝试使用消息有效负载也不起作用:
$msg = array
(
"webpush" => array
(
"notification" => array
(
"title" => "Fish Photos 🐟",
"body" => "Thanks for signing up for Fish Photos! You now will receive fun daily photos of fish!",
"icon" => "firebase-logo.png",
"image" => "guppies.jpg",
"data" => array
(
"notificationType" => "fishPhoto",
"photoId" => "123456",
),
"click_action" => "https://example.com/fish_photos",
"actions" => array(
0 => array(
'title' => 'Like',
'action' => 'like',
'icon' => 'icons/heart.png',
),
1 => array(
'title' => 'Unsubscribe',
'action' => 'unsubscribe',
'icon' => 'icons/cross.png',
),
),
),

),
);

最佳答案

在 Android 上,您必须使用 RemoteInput 并对通知“应用”操作。以下是摘要和here是细节。

public static final String NOTIFICATION_REPLY = "NotificationReply";

RemoveInput removeInput = new RemoteInput.Builder((Notification_REPLY))
.setLabel("Approve Comments")
.build();

然后为回复操作创建一个 PendingIntent ,如下所示:
PendingIntent acceptPendingIntent = PendingIntent.getBroadcast(
context:this,
REQUEST_CODE_APPROVE,
new Intent(packageContext:this,NotificationReciver.class)
.putExtra(KEY_INTENT_APPROVE,REQUEST_CODE_APPROVE),
PendingIntent.FLAG_UPDATE_CURRENT
);

然后使用 addRemoteInput() 将 RemoteInput 对象附加到操作
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(ic_delete,
title:"Approve", acceptPendingIntent)
.addRemoteInput(remoteInput)
.build();

最后,您必须将操作应用于通知和显示。
NotificationCompat.builder = notificaitonBuilder = new NotificationCompat.Builder(context:this,channelId:"channel_id")
.addAction(action)
// set rest of notification attributes e.g. title, auto cancel, icon etc.

您可以从 Firebase 通知的“数据”属性传递所需信息。您甚至必须使用 onReceive() 在消息底部附加回复/按钮。

This是另一个有用的链接。

enter image description here

关于firebase-cloud-messaging - Firebase FCM 通知添加操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57917178/

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