ฉันกำลังพยายามสร้างแอปพลิเคชัน 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());
นี่คือลักษณะที่ปรากฏ:
หลังจากปัด:
มันควรจะอยู่ในหน้าเดียว โดยมีปุ่ม Action ฝังอยู่ในการแจ้งเตือน เช่นนี้
ผมทำอะไรผิดหรือเปล่า?
.extend(new NotificationCompat.WearableExtender().setContentAction( /* HERE */ ));
- person Budius   schedule 08.08.2014