PackageManager pm = context.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_WIFI)) {
...
}
// create notification using a builder
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setContentTitle("Title")
.setContentText("Short message")
.setContextnIntent(pendingIntent) ...;
// add a action to show on Phone and Wearable
notificationBuilder =
.addAction(iconRes, "ActionTitle", pendingIntentAction1);
// show the notification
notificationManager.notify(notificationId, notificationBuilder.build());
// create the Wearable action
NotificationCompat.Action wearableAction =
new NotificationCompat.Action.Builder(iconRes,
"WearableActionTitle", pendingIntentAction2))
.build();
// add the Wearable Action to the notification
notificationBuilder.extend(wearableAction);
// show the notification just on the Phone
notificationBuilder.setLocalOnly(true);
// Create second page notification
Notification secondPageNotification =
new NotificationCompat.Builder(this)
.setContentText("2nd Page Context")... .build();
// Wrap second page in WearableExtender and extend
// the main notification
Notification twoPagesNotification =
new WearableExtender()
.addPage(secondPageNotification)
.extend(notificationBuilder)
.build();
notificationManager.notify(notificationId, twoPagesNotification);
// Create intent for reply action
Intent replyIntent = new Intent(this, ReplyActivity.class);
PendingIntent replyPendingIntent =
PendingIntent.getActivity(this, 0, replyIntent, 0);
// Key for the string that's delivered in the action's intent
private static final String EXTRA_VOICE_REPLY = "extra_voice_reply";
String replyLabel = getResources().getString(R.string.reply_label);
String[] replyChoices = getResources().
getStringArray(R.array.reply_choices);
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel(replyLabel).setChoices(replyChoices)
.build();
// Create the reply action and add the remote input
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon,
getString(R.string.label, replyPendingIntent))
.addRemoteInput(remoteInput)
.build();
// Build the notification and add the action via WearableExtender
Notification notification =
new NotificationCompat.Builder(mContext)
...
.extend(new WearableExtender().addAction(action))
.build();