Android set dynamic icons - android

I'm developping a notification App, I want to know if there is a way to dynamically set the Application icon when I recive a new Notification like happen in Whatsapp, with the circled number on the top of the icon,
thanks :)

There is no such feature available in android OS itself. The notification badge and dynamic icon like in weather and calendar apps purely depends on the launcher app you are using. For example, Samsung can ship a Samsung calendar app on Samsung devices. Samsung's home screen on those same Samsung devices can have special rules for rendering an icon for Samsung's calendar app, rules that involve showing the day of the month. This is because Samsung wrote the home screen.
Hope you understand the scenario.

Related

force android use square launcher icon

I want to use the square version of my launcher icon but somehow android keeps forcing use the rounded version.
I read forcing square app icon and although the explanation makes sense it is not true:
in this screenshot you can see that most of icons are rounded but you have
contacts, widget preview and terminal emulator
And before someone say "they are special apps" terminal emulator is a shit app i downloaded from play store... In my cellphone 80% of apps are rounded but instagram, booking and some others are square...
how to force android use my square launcher?
There is a solution for this which i have tried and its works for me.
What we have to do is take the app icon and keep in res -> drawable.
App icon should be in all formats:-
mdpi
, hdpi
, xhdpi
, xxhdpi
, xxxhdpi
with same name for example-
ic_app_icon.png(mdpi)
ic_app_icon.png(hdpi)
ic_app_icon.png(xhdpi)
ic_app_icon.png(xxhdpi)
ic_app_icon.png(xxxhdpi)
Then in Android Menifest file do this change
android:roundIcon="#drawable/ic_app_icon"
by this we can get app icon square.
First, please understand that there are hundreds of different launcher implementations in use across the ~10,000 Android device models and ~2 billion Android devices. How a launcher chooses to represent your activity is up to the developer of the launcher. For example, there is no requirement for the launcher to use any icon at all (e.g., a launcher optimized for screen readers and visually impaired users). A launcher that does use some sort of graphical element might use your icon or not, and if if it does use your icon, it might modify it (crop it to a shape, apply a color filter, cause it to spin, whatever).
Your screenshot appears to be of the Android emulator. In that case, temporarily, you can set your targetSdkVersion to be 25 or lower, and that particular launcher will not attempt to adapt your launcher icon.
However, please bear in mind that you will not be able to ship your app on the Play Store with that low of a targetSdkVersion starting in a few months. So, if the Play Store is your planned distribution channel, you will need to get used to Android's adaptive icon system and deal with the fact that the shape of your icon will be changed on most Android 8.0+ devices.

How to change Android Oreo launcher icon daily? [duplicate]

I wanna create an Android application, and I want to dynamically and automatically update the app icon similarly to how the calendar icon updates on a user's homescreen.
The calendar changes its icon for each day showing day of month's number. There is also an Alarm clock app which changes its icon setting the current time, in other words, changing every minute.
That isn't a widget, but a real app icon. Then it must have a way to do so. How can I do it in my app?
Whatever your home screen is has special hooks for whatever your calendar app is and whatever your alarm clock app is. In general, apps cannot update their icons.
What do you mean by hooks?
For example, Samsung can ship a Samsung calendar app on Samsung devices. Samsung's home screen on those same Samsung devices can have special rules for rendering an icon for Samsung's calendar app, rules that involve showing the day of the month. This is because Samsung wrote the home screen. If you install a third-party home screen, it may not do the same thing. After all, I can write a home screen in an hour or so, and I feel quite confident that I don't have to do anything special for Samsung's calendar app.
There's nothing stopping Samsung from exposing some sort of API to allow developers to hook into Samsung's home screen and notify it about this sort of thing. Whether Samsung intends for third parties to use that API, or whether it is somebody hacking into how Samsung does it for their own apps, I can't say.
(BTW, I am citing Samsung here as a possible example -- I don't know that they actually have this sort of feature, and if so on which devices they have it)
I seem to recall that somebody has a GitHub project that tries to wrap the proprietary APIs of various home screens. IIRC, some supported capabilities included either replacing the app icon or adding a badge (e.g., unread message count). However:
Only a small percentage of devices will support those proprietary APIs
Undocumented and unsupported APIs, discovered through reverse-engineering apps, are subject to change and may break in unexpected ways
I am quite certain that there is nothing in the Android SDK that supports dynamic app icons. The only thing that I know of, that people have tried, is using <activity-alias> to have N different "activities", all pointing to the same implementation, but having different icons. Using PackageManager and setComponentEnabledSetting(), the app disables the old launcher alias and enables a different one, in hopes that home screens will pick up on this and show the new icon. A few do. Others only would find out about the change on a reboot.
To flip the problem around, I can write a home screen. Perhaps I want to offer some way for apps to change their icons on the fly, even though there are no standards for it. Perhaps I don't. Perhaps I do not intend to use icons at all, as my home screen is optimized for the visually impaired, and so it is using text-to-speech and hardware key input. It's my home screen implementation, and I can do what I want.
Indeed even in the app drawer in Android O, the Clock app icon shows the current time and the Calendar app icon shows the current day-of-month.
This article explains:
Chris Lacy, the developer behind the well-known Action Launcher, has uncovered something in the APK file of the Clock app that comes in Android O: the manifest.xml mentions hours, minutes, and seconds as layers with default values, and the icon has separate images for the background and different elements.
That logically lead him to deduce that starting with Android O, the Clock app's icon will be animated to show the current time. That will happen both when the Clock is placed as a shortcut on the homescreen and when it's inside the app drawer.
It sounds like the Pixel launcher selects different icon image layer resources depending on time and date.
I'm a launcher developer.
I did nothing related to dynamic icon hooks. I just get the activities' icons by the standard way provided by Android API.
And I found that my launcher do show the current time in the Clock app icon and the current date in the Calendar icon.
The device is a Nubia X which runs Android 8.
The operating system should have done something with the two apps and changed their icons dynamically without the launcher beings aware of it.
These two apps are developed by the device manufacturer. You should not be able to do the same thing in a normal way as a third party developer.
you can define multiple activity-alias in your manifest file for each icon
<activity-alias
android:name="OneLauncherAlias"
android:enabled="true"
android:icon="#drawable/one"
android:label="One"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
Enable and disable the activity-alias based on your requirement.
packageManager.setComponentEnabledSetting(ComponentName(this#MainActivity, com.misles.dynamiclaunchericon.OneLauncherAlias::class.java), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP)
packageManager.setComponentEnabledSetting(ComponentName(this#MainActivity, com.misles.dynamiclaunchericon.TwoLauncherAlias::class.java), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP)
for details refer this article
https://medium.com/#simonmisles/dynamic-launcher-icon-and-name-for-android-e40bf0561715
I have the same question but the answer provided here does not aswer it.
I have Google Pixel 2 with raw Android Ore 8.1 on the board and there are two apps that are changing over time: Calendar and Clock. The hands on the clock of Clock app show current time and the number on the Calendar icon correspond to today date of month.
So taking into account that it is default launcher probably there is some API to do similar thing.
For instance it might be the planetary app that reflects planets' positions on the icon. Or memory cleaner that shows percentage of used memory...
The launcher handles the dynamic calendar by accessing an icon for each day from the calendar app. For example, with Google Calendar, a Launcher developer may do the following:
Resources res = activity.getPackageManager()
.getResourcesForApplication("com.google.android.calendar");
int resId = res.getIdentifier("logo_calendar_01_regular", "drawable"
, "com.google.android.calendar");
Drawable icon = res.getDrawable(resId);
This would access the calendar icon for Day 1 of the month. To access any other day, "logo_calendar_01_regular" would be changed for the current day. For example, day 7 would be "logo_calendar_07_regular". Also Google calendar has two styles, "logo_calendar_01_regular" and "logo_calendar_01_round".
Also Icon themes contain separate icons for each date as well.
Adding more context here to #commonsware's answer.
Did a bit more digging on how google does it with their calendar and clock app.
They seem to have special cases in the launcher code as seen here:
https://cs.android.com/android/platform/superproject/+/master:packages/apps/Launcher3/src/com/android/launcher3/icons/IconProvider.java;l=54;drc=337c81f6646e8d8351604ee2e1dd1884bc7d0452
and here:
https://cs.android.com/android/platform/superproject/+/master:packages/apps/Launcher3/src/com/android/launcher3/icons/IconProvider.java;l=74;drc=337c81f6646e8d8351604ee2e1dd1884bc7d0452
So only workaround at this time to do this is to have multiple
activity aliases with different icons and then switch between those aliases.
http://blog.jakelee.co.uk/programmatically-changing-app-icon/

My application breaks phone or some other apps' Notification Icon, Android

I have an interesting problem, my phone model is LGP800 and Android 4.1.2.
I'm developing an application and i'm using camera in this application. When I capture any photo for post, my phone behaves abnormally and other signs (notification icons of apps) also get broke sometimes. I can't find problem like this that nobody hasn't confronted it before. An example secreenshot
Like this picture, my application shows some weird screen or even phone's other apps' notification icon get broke by my application. Example; my wi-fi icon on the tab bar was broken.
Can anyone help, any help is appreciated.!
And also when I capture any picture, it is taken like that;
İt is taken broke, too.

How to automatically add widget to the lock screen 4.2

I want my music widget to be shown on the screen in a similar way that RemoteControlClient works. I don't want the users to be needed to have the widget added to the lock screen beforehand. The samsung music app on thier 4.2 devices have this behaviour.
AFAIK, this isn't possible in the public SDK. Samsung's apps may be able to do it on their device because they are developed by Samsung for their own devices and have greater access as preinstalled system apps.
No API that I am aware of does this as of now.

How do I set up HTC Sense and Samsung Touchwiz app icon badges?

Stock Android doesn't support 'badges' (e.g. unread count on a messaging app) that overlay the app icon like on the iPhone. There are a number of questions here on Stackoverflow which confirm this and suggest using a widget.
Whilst widgets are lovely things, they require too much interaction from the user to get in place (all that searching, long pressing etc.) and don't actually change the app icon. So no, that is not an option.
I accept that Android doesn't have app icon badges. However, HTC Sense and Samsung TouchWiz do. I'm looking at my Galaxy S right now, and the app launcher Messaging icon has a badge with the number of unread SMS messages.
Does anyone know how to access this badge functionality individually for Sense and TouchWiz devices? (I expect there are two APIs).
I don't know about HTC but I've written up how to do this on Samsung phones here How to interface with the BadgeProvider on Samsung phones to add a count to the app icon?
Does anyone know how to access this badge functionality individually for Sense and TouchWiz devices? (I expect there are two APIs).
Become an employee of HTC or Samsung, respectively.
HTC might start offering an API for stuff like this through Open Sense. Samsung might start offering an API for stuff like this through their developer site. I am not aware that either are at present and I wouldn't count on it becoming available.
What you are seeing is a feature of those home screens. You are, of course, welcome to write your own home screen where you have this functionality, perhaps even exposing an API for third-party developers to use.
Still no positive answer to this?
It's very strange that they (HTC and Samsung) haven't come up with a way for third-party apps to update their widgets! So we end up with users of third-party sms apps to complain about the sms counter not updating when it should. This is very sad, especially on the Android world where app integration has been made so easy by the framework! Such implementations should be negatively judged by Android community and the Android Alliance!
If anyone has found a work-around for force updating the widgets of the vendor specific sms apps (HTC and Samsung), so the unread sms counters correctly update, and would like to share this knowledge, you are more than welcome!

Categories

Resources