Set background color of wearable notification - android

I want to set the background color of a notification in a wearable device. The only method that I found is setBackground(Bitmap background) of NotificationCompat.WearableExtender but this is only for bitmaps. Is it a good idea to create a bitmap rectangle and use this as the background of my notification?
Any help would be appreciated.

Use NotificationCompat.Builder, in this one you can use setColor and add it to NotificationCompat.WearableExtender with the method .extend(). like this:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("Title");
builder.setColor(COLOR HERE);
NotificationCompat.WearableExtender builderExtended = new NotificationCompat.WearableExtender();
builderExtended.extend(builder);
builder.build();

Related

Whole Notification Background Color

I'm seeing some apps showing background color in whole notification.
Myntra Notification with BackgroundColor
First Cry Notification with BackgroundColor
I tried solutions from these links but nothing worked.
Changing Notification RemoteViews Background Color
https://cazimirroman.medium.com/android-how-to-set-the-background-color-for-a-notification-in-a-foreground-service-eaa505e2b82d
Tried using DecoratedMediaCustomViewStyle ->
val mediaSession = MediaSessionCompat(context,"tag")
mediaSession.setFlags(0)
mediaSession.setPlaybackState(PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_NONE,0,0f)
.build())
val builder = NotificationCompat.Builder(context, "channelId1")
.setSmallIcon(R.drawable.ic_notification_small)
.setContentTitle("The Title")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setAutoCancel(true)
.setColor(ContextCompat.getColor(context, R.color.pink))
.setColorized(true)
.setStyle(androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().setMediaSession(mediaSession.sessionToken))
In this case notification is coming black always (suppose to be pink) and also doesn't show all the information.
Notification using MediaStyle
You should create two custom layouts for your notifications, one for a collapsed notification and one for an expanded notification, then in your activity:
RemoteView collapsedRV = new RemoteViews (getPackageName(), R.layout.collapsed_notification)
RemoteView expandedRV = new RemoteViews (getPackageName(), R.layout.expanded_notification)
then in your builder you need to set the content view like this:
.setCustomContentView(collapsedRV)
.setCutomBigContentView(expandedRV)
.build()
notificationManager.notify(1,builder)

How to change the background color of notification on Android 12

I would like to make the notification look a different color completely, I am using local notifications so I would like to be able to do this with NotificationCompat.Builder if possible.
Here's an example of what I would like the notification to look like:
Using notification builder methods
NotificationCompat.Builder(context, channelId)
.setColor(ContextCompat.getColor(this, R.color.primaryColor))
.setColorized(true)
.....
.build()

Android custom notification

How to make a custom notification the like a picture attachment.enter image description here
Do you have any suggest or idea for it?
You can use RemoteViews for this
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.YOUR_CUSTOM_LAYOUT);
contentView.setImageViewResource(R.id.YOUR_IMAGEVIEW_ID, YOUR_ICON);
contentView.setTextViewText(R.id.YOUR_TEXT_VIEW_ID, YOUR_NOTIFICAITON_TEXT);
You can add more parameters and customize it more, you have to read the RemoveViews documentation.
Then you create a NotificationCompat.Builder and add contentView as a content from NotificationCompat.Builder something like this :
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(YOUR_CONTEXT)
.setContent(contentView);
Then create the Notification
Notification mNotification = mBuilder.build();
mNotificationManager.notify(1, mNotification);
Those are the simple steps, now you can adjust it to your liking.
Also you can see this example on YouTube or this Tutorial

Set Title of bigpicyure style notification 2 liner Android

I am able to generate notification using BigPictureStyle Notification but its title is coming only in one line but I want it to be two liner instead of continuation symbol.
Code is to set notification style big
picture
NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
notiStyle.setBigContentTitle(headline);
notiStyle.bigPicture(remote_picture);
By this code I am creating notification and setting setStyle with my bigpicture Style notification
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.wrap_up_logo).setAutoCancel(true)
.setLargeIcon(icon).setContentIntent(resultPendingIntent)
.setContentTitle(headline).setStyle(notiStyle).build();
This is the notification i am receiving

Can't add page to Android Wear notification without the card background

It's quite possible Android Wear just doesn't support this but there seems there should be some workaround. I want to add a custom second page to a notification, but I don't want it to have the white card background.
Here's how I create my notifications:
Intent secondPageIntent = new Intent(this, SecondPageActivity.class);
PendingIntent secondPagePendingIntent = PendingIntent.getActivity(this, 0, secondPageIntent, 0);
Notification secondPageNotification = new NotificationCompat.Builder(this)
.extend(new NotificationCompat.WearableExtender()
.setDisplayIntent(secondPagePendingIntent)
.setHintShowBackgroundOnly(true)
)
.build();
Intent firstPageIntent = new Intent(this, FirstPageActivity.class);
PendingIntent firstPagePendingIntent = PendingIntent.getActivity(this, 0, firstPageIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.extend(new NotificationCompat.WearableExtender()
.setDisplayIntent(firstPagePendingIntent)
.setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background))
.addPage(secondPageNotification)
);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(curNotificationId++, builder.build());
I've tried:
Setting setHintShowBackgroundOnly which doesn't do anything
From within SecondPageActivity, try to grab parentActivity and set it's alpha to 0. Doesn't work, parentActivity is null.
Calling setCustomContentHeight(0) doesn't remove the card, it just gets skinny
I tried not using a second page but instead launching an activity when the user swipes but it doesn't look good
I really have no idea what to try next. I'm an experienced engineer but pretty new to Android. Any ideas or suggestions would be helpful.
Thanks!
If you want to get rid of the white card you have to set
setCustomSizePreset(WearableExtender.SIZE_FULL_SCREEN)
So instead of something like that:
your custom content will appear on entire screen (without the card decoration).
Please notice that the background of your custom activity is defined by the style declared in manifest. Unfortunately any theme with transparent background won't work, so the background needs to be opaque:(
This is submitted as an issue here: https://code.google.com/p/android/issues/detail?id=73900
I really hope that they will allow transparent backgrounds there in future:\

Categories

Resources