How to add Icon in Android Application ? - android

I have seen in android native Email application that it updates the icon by showing how many new mails are there ?
Is it a service that updates the icon or is it a process who does it ?
Can someone tell me which file does this change ?

It cannot be done from the application. There are two ways that I know of to achieve that:
A widget that updates itself and changes its icon (but it's not a regular icon to an app)
Some launchers do that on regular icons (e.g. GoLauncher) but they do that from the launcher application code itself: they have a plugin that checks for pre-defined services (mail, Gmail, text messages, missed phone calls, etc.) and then draw a little notification on top of the application icon.

There is no line of code that can do that, at least not in Gingerbread...
What you can do (and that's what most applications that do that use) is create a 1x1 widget that updates its "number of events" whenever an event occurs.
for some information about widgets and remoteViews you can go to:
http://www.vogella.de/articles/AndroidWidgets/article.html
or just google it...

Related

How do I issue conversation notifications on Android 11, if I already have published 5 shortcuts?

According to “People and conversations”, one of the prerequisites for a conversation notification on Android 11 is the following:
The notification is associated with a valid long-lived dynamic or cached sharing shortcut. The notification can set this association by calling setShortcutId() or setShortcutInfo().
But I can only have 5 shortcuts. Does this mean that I can't make conversations notifications for more than 5 people?
It appears that you can actually publish more than 5 shortcuts. You can make notifications which would rank lower than all others by setting rank to a high number, and publish them using shortcutManager.pushDynamicShortcut().
In case you don't have any launcher shortcuts, the above action will create one. If you don't want that, it's recommended to... simply remove the shortcut you just created:
Q: Will my shortcuts appear in the long press app launcher context menu?
A: They can depending on their rank, but if you prefer not having shortcuts appear on launcher you can remove the shortcut with ShortcutManager#removeDynamicShortcuts() or #removeAllDynamicShortcuts() after sending the notification. You can also rank other app shortcuts with higher ranking, so only those dynamic shortcuts appear on launcher.
Some thoughts follow below. It appears that shortcuts on a regular phone will appear in three places:
launcher— either by long pressing app icon, or pinned;
direct share;
conversation notifications.
These shortcuts all come from the same pool. It makes sense, but as there is only a single rank for every shortcut this means that the launcher list and the direct share list are the same. This is something you might not want; you might be sharing more to one conversation but opening another one more often. In my app, I solved this in the following way:
I maintain statistics of when the user shares to a contact / opens a chat with a contact
Whenever the list of top used/top shared contacts change, I update the shortcut using shortcutManager.pushDynamicShortcut(); if a shortcut with the same id already exists, it is updated. I use the old details from shortcutManager.getShortcuts().
depending on whether a shortcut becomes or ceases to become a direct share target, I set or unset a category
specifying rank allows reordering shortcuts in the launcher
Whenever I need to push a notification, I check if I already have a shortcut for the conversation. If not, I simply create a new one with a rank of 10000.
This allows having completely different launcher & direct share shortcuts, and to publish many a conversation notification.
Some random observations:
Adding a shortcut id to a conversation notification also adds its icon to the notification, even if you don't set one explicitly.
shortcutManager.maxShortcutCountPerActivity actually returns 15 (!) on my device (LineageOS), even though the launcher & direct share only show the regular 4 icons.
If you update a shortcut name and/or icon, most of the time it will instantly update in launcher. This includes pinned shortcuts.
Use IconCompat.createWithAdaptiveBitmap() to create icons that work well for various icon shapes. The system will keep a hold of the image, you don't need to keep it. See the documentation for that method.
There are two other methods to be aware of:
IconCompat.createWithAdaptiveBitmapContentUri() is the same as the above but will work with content URIs. This is good for creating Person for notifications, as this allows not keeping the icons in memory. However, there is seemingly no way to pass URI permissions to shortcut manager, so this method can't be used. (Please correct me if I'm wrong here!)
Edit: if you cancel the notification after inline (direct) reply, the system might decide to add your reply to it instead of actually cancelling it. Apparently it might lose URI permissions at this point. Calling this workaround on URIs seems to be helping:
fun Uri.grantReadPermissionToSystem() {
applicationContext.grantUriPermission("com.android.systemui", this,
Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
IconCompat.createWithData() creates memory efficient icons from compressed image data (PNG/JPEG). It's not adaptive, however. And, icons made with it don't work with ShortcutManager at all.
Also don't forget to check out the readme of the People sample app.

How to add an icon to the Android status bar without creating a notification?

I have read: https://developer.android.com/guide/topics/ui/notifiers/notifications.html but I cannot see how to display an icon on the top of the screen, without making a notification.
I have an app with a long-running service, and I want to show an icon that reflects the internal state of that service, at the top of the screen.
How can I do this?
I want to show an icon that reflects the internal state of that service, at the top of the screen. How can I do this?
Make a Notification.
Or, download Android's source code, modify it to allow random apps to put icons in the status bar that the user cannot control, build your modified version of Android, package that into a custom ROM, and convince people to use your custom ROM on their devices.
The only non-Notification status bar icons that apps can semi-directly control are:
whether there is a GPS-active icon, by registering for location updates
whether there is an alarm-clock icon, by using setAlarmClock() on AlarmManager

Working of Count/Badges in Android?

I want to know how does notification read and unread functionality works in android. I want to know how the badges number count is set visible and invisible on read and unread message method.
When I create notification in my application then it will create successfully and add with +1 increment on badges. But after read this notification all other unread notification will also disappear. I want only the reeded message notification/count will be disappeared not for all.all other those are not open will be remain unread on badge. how could I did this.
same like as our message box functionality.
I want to know how the badges number count is set visible and
invisible on read and unread message method
No there is no any direct method to do this. but i show you one way how to achieve this. This solution only working in SAMSUNG Devices. There is no guaranty it's working on all devices.
https://github.com/eldhosembabu/mathokkil/
also another way is you can achieve this by App Widget Provider in Android. for more information go to AndroidWidgets
If you want to put it on Launcher Icon , then in android its not by default functionality given. The reason behind it is, when apk is generated, apk will not find that icon attached with it, so that is the main reason.
Alternate is, you can create widget for it. Creating widget is only solution to achieve this.

Notification badge/counter in control app

I am working on a control-based (V2.0) SW2 app. Is it possible to set the badge-number (i.e. the notification counter) on the icon in the application view used in a notification-based app? I do not need anything else from the notification API, I just want to be able to set the badge-number and removing it after the user opens the control-based app.
Thank you,
Andrej
Unfortunately that is not currently possible without using both the Control and Notification APIs together. If you use both of them in your extension you may be able to achieve something similar to what you want but with the limitation that the extension will always start in Notification mode (this is a bug in the current implementation) so you wouldn't be able to go straight into the Control part of your extension.

how to show local push notification (on app icon on home screen like i-phone) in android

I am given a task to show local push notification. I have successfully completed showing push notification on bar. But also I have to show local notification on app launching icon on home screen like in i-phone. See the image
I want this kind of notification. Here, may be the dialog I create using custom AlertDialog. But I'm stuck with the notification on the app icon i.e. that bubble containing notification no on upper right corner of app icon. I think this functionality is not given by android sdk. but our client says that she has seen these kinds of notifications on her Android mobile for some applications.
So is it possible in Android, and if yes then how to do it?
What you're looking for is a "badge" and I'm sorry to tell you that this does not exist on Android - your client must be mistaken.
One workaround you could do is to create a widget for your app (and you can even make it look like an app icon if you wish...), and you can add a badge or update how it looks any way you choose.

Categories

Resources