简体   繁体   English

Android Wear修改“打开电话”按钮意图

[英]Android Wear modify “Open on Phone” button intent

I am trying distinguish if a notification was opened from the watch or the phone. 我正在尝试区分手表或手机是否打开了通知。 Currently I am trying to set the contentIntent for the notification builder which also appears on the watch as an "Open on phone" action. 目前我正在尝试为通知构建器设置contentIntent ,该构建器也会在手表上显示为“打开电话”操作。 I want to be able to set a different intent just for the watch so that I can add other parameters to the intent, but I cannot find the right way to do it. 我希望能够为手表设置不同的意图,以便我可以为意图添加其他参数,但我找不到正确的方法。

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
        notificationBuilder
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setContentIntent(contentIntent)
                .extend(wearableExtender)

I've tried to add a wearable extender and the action for "Open on Phone" stopped working. 我试图添加一个可穿戴扩展器,“打开电话”的操作停止工作。 I want to know if there is a way to disable the "Open on Phone" button for the wearables and still maintain a setContentIntent() for the phone notification? 我想知道是否有办法禁用可穿戴设备的“打开电话”按钮并仍然保持电话通知的setContentIntent() I've also tried setContentAction() on the extender and "Open on Phone" button, but it still doesn't work. 我也在扩展器和“打开电话”按钮上尝试了setContentAction() ,但它仍然无效。

Any ideas on how to get this working? 关于如何使这个工作的任何想法?

There is no known way to disable the primary action button when you set a PendingIntent to the notification. PendingIntent设置为通知时,没有已知的方法可以禁用主要操作按钮。

According to the developer site for Android wear , the primary action 'Open on phone ' button is automatically defined by setContentIntent() . 根据Android Wear开发者网站 ,主要操作“打开电话按钮由setContentIntent()自动定义。 So if you have PendingIntent associated with the notification on the handheld device, it is going to be automatically carried over to the wearable device with the default action button with same PendingIntent . 因此,如果您的PendingIntent与手持设备上的通知相关联,则会使用具有相同PendingIntent的默认操作按钮将其自动转移到可穿戴设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM