4

At the Google I/O Bytes video How We Customized Google Apps for Android Wear (https://www.youtube.com/watch?v=o5cne6vK-eo), I saw that for the Wearable-customized Camera App, they add a button directly on the notification (not at the back of the notification as a new page which would happen if addAction or setContentAction is used).

Does any one know which API I need to use in order to do that? I don't think there are using a custom Activity for the first view cos it just looks like the first screen of Android Wear when there is at least one Notification. I've tried to find for it in the documentations but couldn't get it. I've tried setDisplayIntent which is suggested by others but it doesn't seems to be the same one.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tamaki Sakura
  • 482
  • 5
  • 22

2 Answers2

5

Use WearableExtender.setContentAction(int) to add an action directly to a notification card. The int parameter refers to the index of the action you have added to the notification (using NotificationCompat.Builder.addAction(NotificationCompat.Action)). See Creating a Notification for more info on how to create notification for wearables.

The sample code you can download using the SDK manager contains a sample project Notifications (located under /samples/android-20/wearable/Notifications) that shows how to create various types of notifications. Here is an edited snippet from that sample that shows how to create a notification with an embedded action:

NotificationCompat.Action action = new NotificationCompat.Action.Builder(
        R.drawable.ic_result_open, null, NotificationUtil.getExamplePendingIntent(
        context, R.string.example_content_action_clicked)).build();

NotificationCompat.Builder builder =
    new NotificationCompat.Builder(context)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle("Title")
        .setContentText("Context Text")
        .addAction(action)
    .extend(new NotificationCompat.WearableExtender()
        .setContentAction(0));
Peter Friese
  • 6,709
  • 31
  • 43
  • Thanks! But I still get one more problem using this code. I still want to keep two button as a page after the first page. But when I do this with `.addAction(R.drawable.button, "Name", pendingIntent)`, the "Name" could not be displayed on the Wearable (the pendingIntent was working properly and I do have a total number of three page). Have you seen this situation before? – Tamaki Sakura Jul 04 '14 at 14:21
  • As soon as you start using wearable actions (using WearableExtender.addAction), regular actions will no longer show up on the wearable. This gives the opportunity to have a different set of actions on the wearable and on the handset. – Peter Friese Jul 05 '14 at 13:20
0

The video walks you though a few steps that are needed, but the main thing (and what you're asking for) is the Wearable Data Layer API. The first view (the card) is a notification, but that notification launches an Activity running on the wear device. That Activity is what displays the button and sends (through the Data Layer API) a message to the camera to take the picture.

ImmortalDev
  • 476
  • 3
  • 5