隐藏可穿戴设备上的打开手机操作 [英] Hide the open on phone action on wearable

查看:63
本文介绍了隐藏可穿戴设备上的打开手机操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何抑制可穿戴设备的打开手机"操作?我添加了一个更有用的自定义操作,现在是双重操作.知道如何删除它吗?

How can I supress the "open on phone" action on a wearable? I added a more helpful custom action which is now a dublicate action. Any idea how I can remove it?

这是我如何构建通知的一个片段:

Here is a snip it how I build the Notification:

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);

我知道我可以创建第二条通知,该通知仅在可穿戴设备上可见,但是Android不需要,因此我需要创建单独的通知吗?

I know that I can create a second notification which is only visible on the wearable but that cannot be wanted by android that I need to create a seperate notification isn't it?

推荐答案

我结束了创建多个通知的过程.这是一个示例:

I ended in creating multiple notifications. Here is an example:

// 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来隐藏其他通知以使其保持同步.

With magic() I create a PendingIntent which invokes a BroadcastReciever which hides the other notifications to keep them in sync.

这篇关于隐藏可穿戴设备上的打开手机操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆