Я пытаюсь создать приложение для Android, которое отправляет уведомление на устройство Android Wear.
В уведомлении должно быть установлено действие с содержимым, чтобы пользователь мог напрямую активировать действие, нажав кнопку, отображаемую в уведомлении.
Однако при использовании приведенного ниже кода действие появляется на следующей странице, как обычное действие, а не в уведомлении:
Context context = getApplicationContext();
// Create an intent for the reply action
Intent actionIntent = new Intent(this, getClass());
PendingIntent actionPendingIntent =
PendingIntent.getActivity(this, 0, actionIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Create the action
NotificationCompat.Action action =
new NotificationCompat.Action.Builder(R.drawable.common_signin_btn_icon_dark, "ActionTitle", actionPendingIntent).build();
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.common_signin_btn_icon_dark)
.setContentTitle("Title")
.setContentText("Context Text")
.addAction(action)
.extend(new NotificationCompat.WearableExtender()
.setContentAction(0));
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
// Build the notification and issues it with notification manager.
notificationManager.notify(0, builder.build());
Вот как это выглядит:
После смахивания:
Предполагается, что все это должно быть на одной странице с кнопкой «Действие», встроенной в уведомление, например:
Что я делаю не так?
.extend(new NotificationCompat.WearableExtender().setContentAction( /* HERE */ ));
- person Budius   schedule 08.08.2014