3

I'm trying to add an action to a notification and display the action buttons even on a wearable device. The following code shows how I create an action and add it to a NotificationCompat which will be delivered using the NotificationManagerCompat as recommended here: 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);

As you can see, I use two different images, one dark and one light for the check-mark and the decline-image. That's because I'd like to have a dark image in the rather light notification area of my Marshmallow test-device and a light image in the rather dark background of the wearable action buttons.

The problem here is that the wearable doesn't display the icon at all. See the following screenshot of my hardware wearable running Android 6.0.1:

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

In reality, there is no black corner. That seems to be a mistake of the screenshot tool of Android Wear. However, I'd like to display the icon on the action button. As all drawables in the project, the done_white/_black and clear_white/black are vector-drawables. I already tried with PNGs as drawables but they didn't work either.

4

1 回答 1

3

I had the same problem because I was using SVG file. When I changed it to PNG it started working.

Solution: use PNG instead of vector SVG

于 2016-06-28T13:14:30.480 回答