In the android clock app icon shows the correct analog real-time in icon, even calendar app icon shows today's date. How to implement real-time icons in apps?
Asked
Active
Viewed 2,444 times
1
-
1There is no general API for dynamic icons like that. Those icons are usually for apps that come packaged with the device/launcher, since it's the launcher app that has to support that functionality. There might be specific launchers out there that do offer some way to do that, but it won't be the same everywhere. – Mike M. Nov 29 '19 at 02:31
1 Answers
-1
You have to create a widget application for this to happen,
https://developer.android.com/guide/topics/appwidgets#
ideally you will have a activity with
<activity android:name=".ClockChoice">
</activity>
which consists of your Analog clock in your xml something like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<AnalogClock
android:layout_marginTop="20dp"
android:layout_marginLeft="120dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
and you add widget following the https://developer.android.com/guide/topics/appwidgets# documentation

Vinay Jayaram
- 1,030
- 9
- 29
-
Thanks. so you are saying that the launcher app by default takes the widget and shows for the app. It seems like just another app icon and not a widget. Widgets we add manually, tell me if there is any way we can forcefully show widget only in place of icon? – pa1pal Nov 28 '19 at 07:05
-
not very much sure if this helps you answer your question https://stackoverflow.com/a/45655507/2850044 – Vinay Jayaram Nov 28 '19 at 07:09