通知操作图标未显示在Wearable上

时间:2016-05-20 08:49:52

标签: android android-notifications android-wear-notification

我正在尝试向通知添加操作,甚至在可穿戴设备上显示操作按钮。以下代码显示了我如何创建操作并将其添加到NotificationCompat,该操作将使用NotificationManagerCompat按照此处的建议投放:https://developer.android.com/training/wearables/notifications/creating.html#Deliver

    NotificationCompat.Action declineActionDark = new NotificationCompat.Action(R.drawable.done_black, getString(R.string.accept), acceptInvitationPendingIntent);
    NotificationCompat.Action acceptActionDark = new NotificationCompat.Action(R.drawable.clear_black, getString(R.string.decline), declineInvitationPendingIntent);
    NotificationCompat.Action declineActionLight = new NotificationCompat.Action(R.drawable.done_white, getString(R.string.accept), acceptInvitationPendingIntent);
    NotificationCompat.Action acceptActionLight = new NotificationCompat.Action(R.drawable.clear_white, getString(R.string.decline), declineInvitationPendingIntent);

    NotificationCompat.WearableExtender wearableExtender =
            new NotificationCompat.WearableExtender()
                    .addAction(declineActionLight)
                    .addAction(acceptActionLight);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
            .setContentText(message)
            .setSound(defaultSoundUri)
            .setSmallIcon(R.drawable.place_white)
            .setLargeIcon(bitmap)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .addAction(declineActionDark)
            .addAction(acceptActionDark)
            .setAutoCancel(true)
            .setPriority(Notification.PRIORITY_HIGH)
            .extend(wearableExtender)
            .build();
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
    notificationManager.notify(notificationId, notification);

正如你所看到的,我使用了两个不同的图像,一个是暗色,一个是用于复选标记和缩小图像。那是因为我希望在我的Marshmallow测试设备的相当明亮的通知区域中有一个暗图像,在可穿戴动作按钮的相当暗的背景中有一个浅色图像。

这里的问题是可穿戴设备根本不显示图标。请参阅运行Android 6.0.1的硬件可穿戴设备的以下屏幕截图:

in reality, there is no black corner. That seems to be a mistake of the screenshot tool of Android Wear

实际上,没有黑角。这似乎是Android Wear截图工具的一个错误。但是,我想在动作按钮上显示图标。作为项目中的所有drawable,done_white / _black和clear_white / black是vector-drawables。我已经尝试过使用PNG作为drawable,但它们也没有用。

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,因为我使用的是SVG文件。 当我将其更改为PNG时,它开始工作。

解决方案:使用PNG代替向量SVG