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.
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?
call setColor -> the color to be used on the background. call setColorized -> the actual call to set the background color.
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.
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.
Green background from your icon color.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With