如何在可穿戴设备上压制“打开电话”动作?我添加了一个更有帮助的自定义操作,现在是一个dublicate行动。知道如何删除它吗?
以下是我如何构建通知:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle("Title")
.setContentText("Message")
.setSmallIcon(R.drawable.icon)
.setContentIntent(openIntent);
NotificationCompat.WearableExtender extender =
new NotificationCompat.WearableExtender();
extender.addAction(new NotificationCompat.Action.Builder(icon, "do something",
openIntent).build());
builder.extend(extender);
我知道我可以创建第二个通知,这个通知只能在可穿戴设备上看到但是我不需要创建一个单独的通知而不是它吗?
答案 0 :(得分:1)
根据documentation"打开电话"如果在PendingIntent
方法中设置了setContentIntent(PendingIntent intent)
,则会自动添加操作。
当此通知出现在手持设备上时,用户可以调用指定的PendingIntent 通过触摸通知的setContentIntent()方法。当此通知出现在 Android可穿戴,用户可以向左滑动通知以显示Open动作,其中 调用手持设备上的意图。
我不认为你可以"禁用"这个动作(除了不指定contentIntent
,但我想这不适合你)。
我不熟悉您的具体情况,但大多数人会在通知上设置contentIntent
以启动显示详细信息的某些Activity
或允许用户执行更多操作(例如输入) ,配置等)。在这种情况下,即使你正在提供某种轻量级的"我也没有必要尝试禁用这个额外的动作。解决方案就在Android Wear设备上。
但是,如果你真的想摆脱这个"打开电话"操作(虽然仍然在手机上设置contentIntent
),您需要从Android Wear设备发布单独的通知。
您需要使用DataApi
来同步通知状态。请参阅文档中有关DataApi
的更多详细信息:
https://developer.android.com/training/wearables/data-layer/index.html
https://developer.android.com/training/wearables/data-layer/data-items.html
另外,您可以查看DataApi
in one of my answers的使用示例。
答案 1 :(得分:1)
我最终创建了多个通知。这是一个例子:
// for the wearable
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle("Title")
.setContentText("Message")
.setSmallIcon(R.drawable.icon)
.setContentIntent(openIntent)
.setGroup("MyGroup")
.setDeleteIntent(magic());
// since I don't set setGroupSummary(true) this
// notification will not been display on a mobile
NotificationCompat.WearableExtender extender =
new NotificationCompat.WearableExtender();
extender.addAction(new NotificationCompat.Action.Builder(icon, "do something",
openIntent).build());
builder.extend(extender);
// fire it
// for the mobile
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle("Title")
.setContentText("Message")
.setSmallIcon(R.drawable.icon)
.setContentIntent(openIntent)
.setLocalOnly(true) // the magic to hide it on the wearable
.setDeleteIntent(magic());
// fire it
使用magic()
我创建了一个PendingIntent,它会调用BroadcastReciever
来隐藏其他通知,以使它们保持同步。