praba buddy praba buddy - 2 months ago 6
Android Question

Buttons in android push notification

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?


You can use .addAction in Notification.Builder.

Notification notification = new Notification.Builder(context)
    // Show controls on lock screen even when user hides sensitive content.
    // 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


Refer this link.