Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Wear - use specified solid color for notification background

For some reason I can't make this simple concept work on Android wear. I want the notification on Wear to have a solid color background with color of my choosing. This is what I'm trying to do:

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder
            .setContentTitle("title")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("Text")
            .setColor(Color.YELLOW);

    Notification notification = builder.build();
    notificationManager.notify(123456, notification);

As you can see, I'm setting the notification color to yellow. And this does set the background on the notification to yellow on the phone. But for some reason, background color on the notification I see on Android Wear is green. Please see attached screenshots.

enter image description here

enter image description here

I tried extending notification builder with a WearableExtender, but it doesn't have a "setColor"-like method, only "setBackground". Why does Wear ignore specified notification color? And where does it take that green background color from? How do I override that color?

like image 310
Anton Cherkashyn Avatar asked Jul 15 '15 21:07

Anton Cherkashyn


People also ask

How do I change the background color on my notifications?

call setColor -> the color to be used on the background. call setColorized -> the actual call to set the background color.

What is NotificationCompat builder?

public class NotificationCompat.Builder. Builder class for NotificationCompat objects. Allows easier control over all the flags, as well as help constructing the typical notification layouts. On platform versions that don't offer expanded notifications, methods that depend on expanded notifications have no effect.

What is ongoing notification?

The notification is the only surface your app will show while running in the background. On Android 11 and higher, Wear OS hides the notification in the notification tray when the app is visible as an ongoing activity on additional surfaces.


1 Answers

Green background from your icon color.

enter image description here

You can call WearableExtender setBackground method

    int notificationId = 001;

    Bitmap bitmap = Bitmap.createBitmap(320,320, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.YELLOW);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("title")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("Text")
            .extend(new NotificationCompat.WearableExtender().setBackground(bitmap));

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(notificationId , builder.build());

enter image description here

like image 104
aiur Avatar answered Oct 07 '22 17:10

aiur