0

Does anybody know how to get Android Notifications quick responses?

Example with image:

enter image description here

I'm Developing an app for sending notifications to a non Android Wear smartwatch (Qualcomm Toq), and I want to add those quick responses options. I get those notifications using NotificationListenerService, but I don't find those quick responses anywhere. Could someone suggest a way?

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
CitoPaez
  • 69
  • 3

2 Answers2

2

I was looking for actions inside StatusBarNotification, but they are in the Notifications object inside StatusBarNotification:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    Notification n = sbn.getNotification();
    for(Action action : n.actions){
        String title = action.title.toString;
        ...
    }
}

Now I hope to find the way to execute those actions when the smartwatch button is clicked.

Thank you all!

CitoPaez
  • 69
  • 3
0

You could use .addAction() method:

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) // #like this
    .addAction(R.drawable.ic_pause, "Pause", pausePendingIntent)  // #this
    .addAction(R.drawable.ic_next, "Next", nextPendingIntent)     // #and this
    // 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();

Source : http://developer.android.com/guide/topics/ui/notifiers/notifications.html#controllingMedia

Randyka Yudhistira
  • 3,612
  • 1
  • 26
  • 41
  • Thank you for the answer, but I want to do the opposite. I have a NotificationListenerService in order to listen to the notifications, but I can not found a way to Get those actions from the StatusBarNotifications. `@Override public void onNotificationPosted(StatusBarNotification sbn) { Log.d("ToqAN", "New notification detected"); ...}` – CitoPaez Feb 18 '15 at 09:30