Possible to continuously update text in the notification area? - android

I would like a to place persistent text in the notification area that updates once every second. setTicker() in the NotificationCompat.Builder class will not work, because it hides everything else in the notification area. I am only looking to place text there that is a few characters long, taking up only a small piece of the notification area.
One way I think this can be done is by calling setSmallIcon(), and somehow using this small icon area to display text. I took a screenshot of an app's notification that I believe to be using this strategy. Notice the 165 KB/s:

You shouldn't use the ticker text of the notification to update the user. This text is shown when the notification is posted.
Like the screenshot it uses setSmallIcon like you mentioned.
You can create a bitmap and draw text on with the canvas API, then updating your current ongoing notification
Example how to draw text on bitmap
This will change the icon in the statusbar and visible for the user.

Related

In android, how to set the 2 small icons visible in the notification

In android notification, it's seam their is 3 different icons (see the picture below). I know how to set the large icon (via setlargeicon), however i don't know how to set the both 2 small icons as their is only one procedure setSmallIcon available.
It is the same setSmallIcon for both locations. However, you can also use setColor() to set the background color on the notification - that is how the lower icon gets the blue background.

Android Notification smallIcon not displaying properly

So I've been working with Android Notifications and after setting a large image, I found out that my small image is actually not displaying properly.
As you can see on the following screenshot of the lockscreen, the background of the small icon is transparent. I want to set a specific colour there, just like the one Outlook.com is using:
Another example where the small icon shows next to the large one (please take notice of the small icon which is actually displaying, but not really noticable because there is just no background):
I've been thinking about changing the small icon to include the background colour, but obviously the colour would also be shown in the statusbar and that's wrong.
Try setColor() with NotificationCompat.Builder to set the accent color, which should be used by the colored circle behind the icon.

Zoomed, cropped icon in notification

I'm creating a notification using NotificationCompat.Builder. To set the large icon part of it, I'm using this:
bob = new NotificationCompat.Builder(context)
.setLargeIcon(bm)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher256)
.setContentTitle(context.getResources().getString(R.string.app_name))
.setContentText(message)
.setPriority(Notification.PRIORITY_HIGH);
The smallicon is displaying fine, but on some devices the large icon is zoomed in, and therefore cropped. On other devices (handily, all the ones I can test it on) it works perfectly.
I'm not aware of any restrictions on what size this icon must be. It's coming out of the users contacts list, so I can't control what goes in there, although I suppose I could resize/reformat it if that were the problem.
I'll continue to debug this (focussing on the logic which obtains the bitmap) but thought I'd ask in case I've overlooked something (non) obvious. Perhaps it's possible for people to set contact photos on their devices which aren't suitable for notifications without some pre-processing.
It's not really documented. :(
You can see from the base template layout that the icon is just dunked in an ImageView with android:scaleType="center", so anything bigger than the box (#dimen/notification_large_icon_widthx#dimen/notification_large_icon_height) will just get cropped as it overflows its bounds.
The answer, then, as you can see from dimens.xml, is 64x64dp. You'll want to scale your Bitmaps accordingly before posting the notification.

How to create a custom notification on Android. Text instead of image

I want to create notification like here:
Red circle = icon which is always visible. Blue circle = icon that is visible only when you expand.
How do I make such a red circle notification?
must I create 100 images or can I use custom notification like text? Can i join two images together?
I found this:
http://www.framentos.com/en/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/
Custom notification layouts and text colors
But I still don't know how to create this red circle. With this i know how to create blue circle but this I don't need. I am not creating battery!
Any ideas?
The only text that you can put in the notification area/status bar ("red circle") is ticker text, which disappears after it's displayed (setTicker). The purpose of that area is to remind users that a notification is outstanding, using the small icon (setSmallIcon). You could make 100 different icons, one for each percentage, but then you would not be using Android's standard design guidelines for notifications.
I suggest that if you want a battery indicator, use 5 battery icons. One icon would be a "full" battery, along with 1 each for 75%, 50%, 25%, and "very low" (in red). I suspect that most users don't need to see exactly how much battery they have left in the status bar. You can then show the exact numbers and estimated time remaining in the full notification.

Android Notification Dynamic Icon

Is it possible to overlay a notification icon with some text/int? or is it possible to generate a custom icon on the fly?
For example I have the current icon displayed for my notification, I would like to be able to display for example the number 2 within the red box.
As this is not a count of notifications ( so not the red bubble ), the setting the "number" in the notification will not work.
Will I have to just create an individual icon for every possible number I wish to display? Or is there a better way of achieving this?
Try using AnimationDrawable's. You can use them to combine multiple drawables into a single one, and select the one you want to display. I really think, this is the way to go.
More info: AnimationDrawable
Off course, you will have to provide individual drawables for all your Integers you want to display, but this way, you can easily change the appearance of your notifications
Notification.Builder
Has two methods:
setLargeIcon(Bitmap icon)
and
setSmallIcon(int icon)
Since the small Icon only seems to take a resource ID I think you'd have to provide a drawable resource for every possible number you want then you could select which one to use at run time.
The Large icon however takes a Bitmap, so you should be able to generate one with some java code and pass it in.
Truthfully though I don't exactly know what the difference is between the Large and Small icons. I don't have much experiences with Notifications in general. You might luck out and find that setLargeIcon will work for what you need. But it might also be that you can only use a Bitmap object for the image that is shown when the notification bar is pulled down, not the one that is shown while it is collapsed.

Categories

Resources