android wear notification with different text styles - android

On Add a Big View Google show how to make use of BigTextStyle. The screenshot looks very promising:
So I can see a title "Emmet Connolly" which I can set with setContentTitle().
And I can see a bold header "Re: wearables" which I don't know how to set.
Finally there is some text "Our devs are goint to be building a lot of really awesome apps" which should be set with setContentText().
I played around with some setters from NotificationCompat.BigTextStyle and I can summarize that some are ignored. Seems to be a bug ?!
final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
.setBackground(BitmapFactory.decodeResource(context.getResources(), R.drawable.chalk));
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("title")
.setContentText("text") // overwritten by bigText()
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("big text")
.setBigContentTitle("big content title") // ignored
.setSummaryText("summary text")) // ignored
.setContentIntent(viewPendingIntent)
.extend(wearableExtender);
final NotificationManagerCompat manager = NotificationManagerCompat.from(context);
manager.notify(notificationId, builder.build());

Html seems to work:
.setContentText(Html.fromHtml("<b>Best</b> restaurant <i>in</i> <font color=\"#0000ff\">San</font> Francisco <a href=\"http://www.stackoverflow.com\">#food"))
An here is a useful link: HTML Tags Supported By TextView

Related

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

Displaying text in Android Status Bar

I am trying to display text in the Status Bar of Android Nougat just as time is displayed. I can display icons using NotificationCompat.Builder but not text. How to proceed?
If you're using NotificationCompat.Builder you can set text there
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
You can also address this
Solved the problem by converting String to Bitmap. Got the idea from here

How to know the picture size in the Android Notification big picture style?

Android Big Picture Style Notification
Sizes for notification images for BigPictureStyle
Minimum - 512x256
Balanced - 1024x512
Maximum - 2048x1024
Got from this answer https://stackoverflow.com/a/33391039/5783417
Note : In smaller devices (800x480), there is still a center crop
occurring
Try this code
Notification notif = new Notification.Builder(mContext)
.setContentTitle("New photo from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_post)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigPictureStyle()
.bigPicture(aBigBitmap))
.build();
To have a notification appear in an expanded view, first create a NotificationCompat.Builder object with the normal view options you want. Next, call Builder.setStyle() with an expanded layout object as its argument.
Remember that expanded notifications are not available on platforms prior to Android 4.1. To learn how to handle notifications for Android 4.1 and for earlier platforms, read the section Handling compatibility.
For example, the following code snippet demonstrates how to alter the notification created in the previous snippet to use the expanded layout:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Event tracker")
.setContentText("Events received")
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Event tracker details:");
...
// Moves events into the expanded layout
for (int i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
// Moves the expanded layout object into the notification object.
mBuilder.setStyle(inboxStyle);
...
// Issue the notification here.
You can also refer to this link, Applying an expanded layout to a notification

how to show only Large icon without small when use NotificationCompat without using small

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(b)
.setContentTitle("this a message!")
.setContentText("Hello world");
can I use only setLagreIcon() or any other alternative solution?
From documentation:
A Notification object must contain the following:
A small icon, set by setSmallIcon()
A title, set by setContentTitle()
Detail text, set by setContentText()
So no, this is not possible.
Edit: A really unsafe and not recommended method seems to be explained here.

Categories

Resources