Android Wear - 通知 - setContentAction()不工作 [英] Android Wear - Notification - setContentAction() not working

查看:119
本文介绍了Android Wear - 通知 - setContentAction()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个通知,大火从可穿戴设备,仅在可穿戴设备,无法在手机上的。我希望它有两个操作按钮(还没有功能)和第三行动通知本身被点击时。我试图用setContentAction()进行的最后一个动作是行动通知被点击时,但它仍然显示为一个单独的操作按钮(根据文档<一href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.WearableExtender.html#setContentAction%28int%29">here它不应该显示一个单独的按钮)。不需要的按钮触发预期的意图,虽然。通知本身没有响应点击。这里是code创建通知:

I'm creating a notification that fires from the wearable device and only on the wearable device, not on phone at all. I want it to have two action buttons (no functionality yet) and a third action when the notification itself is clicked. I'm trying to use setContentAction() to make the last action be the action when the notification is clicked, but it's still displaying as a separate action button (according to the documentation here it shouldn't display a separate button). That unwanted button fires the desired intent, though. The notification itself isn't responding to clicks. Here is the code to create the notification:

    Intent pictureIntent = new Intent(this, PictureActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 254, pictureIntent, PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.medicinepillmd)
                    .setContentTitle(dose[0])
                    .setContentText(dose[3])
                    .extend(new NotificationCompat.WearableExtender()
                            .setContentIcon(R.drawable.thumbnail)
                            .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.orangegirl))
                            .addAction(new NotificationCompat.Action.Builder(R.drawable.medicinepillmd, "Taken", null).build())
                            .addAction(new NotificationCompat.Action.Builder(R.drawable.thumbnail, "Skipped", null).build())
                            .addAction(new NotificationCompat.Action.Builder(0, null, pendingIntent).build())
                            .setContentAction(2));

任何人都知道为什么,这可能不是表现为故意的吗?任何输入AP preciated。谢谢

Anyone know why this might not be behaving as intended? Any input appreciated. Thanks

推荐答案

setContentAction(INT指数)允许您指定将合并成牌的动作。它不删除操作页面这一行动,也只会是present你的主卡。但是你的问题的原因是,你没有指定你的动作图标资源。而不图标它不能被合并到主卡

Reason:

setContentAction(int index) allow you to specify an action that will be "merged" into the card. It DOES remove this action from "action pages" and it will only be present at your main card. However the reason of your problem is that you do not specify the icon resource for your Action. Without icon it cannot be merged to the main card.

您需要指定一些图标,并把它添加到你的行动:

You need to specify some icon and add it to your action:

.addAction(new NotificationCompat.Action.Builder(R.drawable.some_icon, null, pendingIntent).build())

如果你真的不想要任何的图标,你可以使用黑客空图标:

If you really do not want any icon you can use a "hack" with empty icon:

empty_icon.xml:

empty_icon.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
</shape>


注意 setContentIntent(PendingIntent意图)不会让你的卡点击。它只是将创建并添加另一个动作(最右)标签:打开


NOTE: setContentIntent(PendingIntent intent) will not make your card clickable. It will just create and add another action (to the most right) with label: "Open".

这篇关于Android Wear - 通知 - setContentAction()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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