android - 禁用 android wear 挂起的 Intent 操作确认

标签 android android-notifications wear-os

我目前正在开发一款带有通知的应用程序,它会显示在可穿戴设备上。通知包含绑定(bind)到通知卡上的操作 (.setContentAction(0))。

enter image description here

一切正常,除了每次有人点击卡片时都会显示一条确认消息。

enter image description here

由于卡片会在有人点击后立即更新,因此无需显示确认信息。

我已经查看了官方文档(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/

相关文章:

android - 水平recyclerview内部垂直recyclerview滚动性能

android - 即使 editText 具有焦点,Talk Back 也会宣布微调器内容描述

android - 圆形按钮组 View

android - 在 Android O 中发送本地通知

安卓 4.1 : How to check notifications are disabled for the application?

android - 如何打开 MIUI 通知设置?

Google Play 开发者控制台上的 Android Wear + 手机应用

安卓磨损 : how to share code between the wearable and handheld modules?

android - 向安卓穿戴设备发送数据

android - 如何使用带有底部导航 View 的全屏 fragment ?