Create GCM Push Messages with Action Buttons

I have seen several applications that send push notifications that have custom buttons for taking certain actions.

I looked at the GCM push notification server document: https://developer.android.com/google/gcm/server-ref.html#table1

but there is no link on how to do this.

+4
source share
1 answer

This is done on the device side, not on the server.

After completing the full implementation of Google Cloud Messaging

Consider creating Notifications on a device.

Here is a snippet representing a notification with the buttons specified in the second link:

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_prev, "Previous", prevPendingIntent) // #0
    .addAction(R.drawable.ic_pause, "Pause", pausePendingIntent)  // #1
    .addAction(R.drawable.ic_next, "Next", nextPendingIntent)     // #2
    // Apply the media style template
    .setStyle(new Notification.MediaStyle()
    .setShowActionsInCompactView(1 /* #1: pause button */)
    .setMediaSession(mMediaSession.getSessionToken())
    .setContentTitle("Wonderful music")
    .setContentText("My Awesome Band")
    .setLargeIcon(albumArtBitmap)
    .build();
+4

Source: https://habr.com/ru/post/1584311/


All Articles