How to add action button to push notification like this:
I tried this and its not working:
=> https://firebase.googleblog.com/2018/05/web-notifications-api-support-now.html
here's my notification payload:
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',
),
),
);
I tried with message payload also doesnt work:
$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',
),
),
),
),
);
Best Answer
On Android, you'll have to use RemoteInput and 'apply' action to the notification. Below is the summary and here are the details.
Then create a PendingIntent for the reply action as below :
Then attach the RemoteInput object to an action using addRemoteInput()
Lastly, you'll have to apply the action to notification and display.
You can pass the required information from the 'data' attribute of Firebase notification. You'll have to use onReceive() even to attach reply/buttons at the bottom of the message.
This is another helpful link.