Saya mencoba membuat aplikasi Android yang mengirimkan notifikasi ke perangkat Android Wear.
Notifikasi harus memiliki tindakan konten yang ditetapkan, sehingga pengguna dapat langsung mengaktifkan tindakan tersebut dengan mengklik tombol yang ditampilkan di notifikasi.
Namun, dengan menggunakan kode di bawah ini, tindakan tersebut muncul di halaman berikutnya, seperti tindakan biasa, dan bukan pada notifikasi:
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());
Begini tampilannya:
Setelah menggesek:
Seharusnya semuanya berada dalam satu halaman, dengan tombol Tindakan tertanam dalam notifikasi, seperti ini:
Apa yang saya lakukan salah?
.extend(new NotificationCompat.WearableExtender().setContentAction( /* HERE */ ));
- person Budius   schedule 08.08.2014