23 5月 2014
Notification notification1 = new WearableNotifications.Builder(builder1) .addPages(extras) .build();
// Nuke all previous notifications and generate unique ids NotificationManagerCompat.from(this).cancelAll(); int notificationId = 0; // Titles, authors, and overdue status of some books to display String[] titles = { "How to survive with no food", "Sailing around the world", "Navigation on the high seas", "Avoiding sea monsters", "Salt water distillation", "Sail boat maintenance" }; String[] authors = { "I. M. Hungry", "F. Magellan", "E. Shackleton", "K. Kracken", "U. R. Thirsty", "J. Macgyver" }; Boolean[] overdue = { true, true, true, true, true, false }; ListFollow these simple steps to see the example in action:extras = new ArrayList (); // Extra pages of information for the notification that will // only appear on the wearable int numOverdue = 0; for (int i = 0; i < titles.length; i++) { if (!overdue[i]) continue; BigTextStyle extraPageStyle = new NotificationCompat.BigTextStyle(); extraPageStyle.setBigContentTitle("Overdue Book " + (i+1)) .bigText("Title: " + titles[i] + ", Author: " + authors[i]); Notification extraPageNotification = new NotificationCompat.Builder(this) .setStyle(extraPageStyle) .build(); extras.add(extraPageNotification); numOverdue++; } // Main notification that will appear on the phone handset and the wearable Intent viewIntent1 = new Intent(this, MainActivity.class); PendingIntent viewPendingIntent1 = PendingIntent.getActivity(this, notificationId+1, viewIntent1, 0); NotificationCompat.Builder builder1 = new NotificationCompat.Builder(this) .addAction(R.drawable.ic_action_done, "Returned", viewPendingIntent1) .setContentTitle("Books Overdue") .setContentText("You have " + numOverdue + " books due at the library") .setSmallIcon(R.drawable.ic_launcher); Notification notification1 = new WearableNotifications.Builder(builder1) .addPages(extras) .build(); // Issue the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notificationId+1, notification1);
import android.support.v4.app.NotificationCompat; import android.app.Notification; import android.app.PendingIntent; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.preview.support.v4.app.NotificationManagerCompat; import android.preview.support.wearable.notifications.WearableNotifications;7. Add the image below to your res/drawable-xxhdpi directory.
res/drawable-xxhdpi/ic_action_done.png