按钮/动作未出现在磨损通知中

时间:2014-08-08 09:28:37

标签: android notifications wear-os

我正在尝试构建一个向Android Wear设备发送通知的Android应用程序。

通知需要设置内容操作,以便用户可以通过单击通知中显示的按钮直接激活操作。

但是,使用以下代码,操作会显示在下一页上,就像常规操作一样,而不是通知:

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());

它的外观如下:

enter image description here

刷完后:

enter image description here

它应该都在一个页面上,操作按钮嵌入到通知中,如下所示:

enter image description here

我做错了什么?

1 个答案:

答案 0 :(得分:1)