解决方法
>手持设备上显示原始NotificationCompat.Builder上添加的操作.
> WearableExtender上添加的操作显示在Android Wear设备上.
见Specifying Wearable-only Actions:
If you want the actions available on the wearable to be different from
those on the handheld,then useWearableExtender.addAction()
. Once you
add an action with this method,the wearable does not display any
other actions added withNotificationCompat.Builder.addAction()
. That
is,only the actions added withWearableExtender.addAction()
appear on
the wearable and they do not appear on the handheld.
因此,要创建仅限手持设备的操作,请在创建扩展程序之前添加它们.要进行仅可穿戴动作,请在扩展器上添加它们.如果您使用扩展器并且想要在两个设备中重复操作,则必须在两者中添加它们(尽管可能有复制它们的选项?).
例如:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("The title") .setContentText("This is the text") .setContentIntent(pendingIntent); // Handheld-only actions. notificationBuilder.addAction(drawable1,"In Both",pendingIntent); notificationBuilder.addAction(drawable2,"Only in phone",pendingIntent); // Wearable-only actions. NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); wearableExtender.addAction(new NotificationCompat.Action.Builder(drawable2,pendingIntent).build()); wearableExtender.addAction(new NotificationCompat.Action.Builder(drawable3,"Only in wearable",pendingIntent).build()); notificationBuilder.extend(wearableExtender); // Build and show notification. notificationmanagerCompat notificationmanager = notificationmanagerCompat.from(this); notificationmanager.notify(notificationId,notificationBuilder.build());
也
>如果您创建了WearableExtender但未向其中添加任何操作,则使用原始通知中的操作.>手持设备的“内容意图”似乎总是出现在手表上,带有“打开电话”文本.我还没有找到一种方法只为手表禁用此功能.
原文地址:https://www.jb51.cc/android/309153.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。