我目前正在开发一款带有通知的应用程序,它会显示在可穿戴设备上。通知包含绑定(bind)到通知卡上的操作 (.setContentAction(0))。
一切正常,除了每次有人点击卡片时都会显示一条确认消息。
由于卡片会在有人点击后立即更新,因此无需显示确认信息。
我已经查看了官方文档(https://developer.android.com/training/wearables/ui/confirm.html#show-confirmation)是否有办法停止确认,不幸的是我目前没有找到解决方案。
编辑 09.07.2015
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setGroup("GROUP")
.setGroupSummary(false)
.setAutoCancel(false)
.setPriority(Notification.PRIORITY_HIGH)
.setSmallIcon(R.drawable.ic_timer_white_48dp);
ArrayList<NotificationCompat.Action> actions = new ArrayList<>();
NotificationCompat.Action control = new NotificationCompat.Action.Builder(icon, null, pendingTimeIntent).build();
actions.add(control);
builder.extend(new NotificationCompat.WearableExtender().addActions(actions).setContentAction(0).setBackground(background));
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(context);
notificationManager.notify(Constants.NOTIFICATION_ID_WEAR, builder.build());
最佳答案
你可以尝试像这样修改你的构造函数:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setGroup("GROUP")
.setGroupSummary(false)
.setAutoCancel(false)
.setPriority(Notification.PRIORITY_HIGH)
.setShowWhen(true)
.setSmallIcon(R.drawable.ic_timer_white_48dp);
注意这一行:
.setShowWhen(true);
并且可以修改Intent的flag为false:
Intent intent = new Intent(this, ConfirmationActivity.class);
intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,
ConfirmationActivity.SUCCESS_ANIMATION);
intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE,
getString(R.string.msg_sent));
intent.putExtra(ConfirmationActivity.EXTRA_SHOW_WHEN, false);
startActivity(intent);
我不知道它是否正常工作,但我希望它能给你一个线索。
关于android - 禁用 android wear 挂起的 Intent 操作确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27754039/