Buttons in android push notification

3.1k views Asked by At

I am doing Push notification message in android devices and follows GCM documentation for my reference and I have scenario that in the notification itself I have to show buttons and user clicked it will trigger the respective actions.

From the GCM documentation, in the notification payload we can add click_action to trigger the action when user touched notification...

How to show buttons (Like Accept/Reject ) in the notification message?

2

There are 2 answers

2
Jay Rathod On BEST ANSWER

You can use .addAction in Notification.Builder.

Notification notification = new Notification.Builder(context)
    // Show controls on lock screen even when user hides sensitive content.
    .setVisibility(Notification.VISIBILITY_PUBLIC)
    .setSmallIcon(R.drawable.ic_stat_player)
    // Add media control buttons that invoke intents in your media service
    .addAction(R.drawable.ic_accept, "Accept", prevPendingIntent) // #0
    .addAction(R.drawable.ic_reject, "Reject", pausePendingIntent)  // #1

// Apply the media style template

EDIT 1

Refer this link.

0
Arthur Thompson On

There is no way to add action buttons to a notification message. This may be a feature added later on but currently it does not exist.

Notification messages allow you to create a very specific type of notification, if you want to have a very custom notification then you should use data messages (not notification messages) and then when the message is received use the Notification.Builder to generate your custom notification with as many features as are available :)