【发布时间】:2014-08-09 05:14:04
【问题描述】:
我正在尝试构建一个向 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());
看起来是这样的:
刷卡后:
它应该都在一个页面上,操作按钮嵌入到通知中,如下所示:
我做错了什么?
【问题讨论】:
-
不完全确定(因此评论而不是回答),但我相信出现在主页内的操作应该在
.extend(new NotificationCompat.WearableExtender().setContentAction( /* HERE */ )); -
@Budius 在示例项目中不是这样,它可以工作(但差异太大,无法直接复制)。我试过了,还是不行。
-
@jco:您指的是哪个示例项目?您是否尝试过stackoverflow.com/questions/25018086/… 或stackoverflow.com/questions/24601352/… 中的建议?
-
@WaynePiekarski SDK 附带的 ContentAction 之一。此外,我几乎可以肯定你上面链接的两个问题解决了我的问题。我将在星期一对其进行测试,如果有问题或足够相似,则将我的问题标记为重复。
标签: android notifications wear-os