Detect long press on the app's icon from the launcher - android

I need to get a notification when the user long-presses my app's icon from the launcher screen.
After a lot of research - I encountered 'app shortcuts' and it seems the closest thing to the functionality I need, though I couldn't find any event or broadcast fired upon long pressing my app's icon.
I don't think this has been answered here before since I'm trying to find a solution for hours now.
I looked into all the tutorials under AD: https://developer.android.com/guide/topics/ui/shortcuts.html
I also tried googling any possible combination might give me some leads, but couldn't find anything.
The functionality in possible (saw another app uses it), though running
dumpsys activity broadcasts
I couldn't find any related broadcast.
Is there's any standard broadcasts fired by the launcher maybe?

Is there's any standard broadcasts fired by the launcher maybe?
Well, there are hundreds, if not thousands, of launcher implementations, both pre-installed and user-installed. There is no requirement for any of them to send a broadcast in any situation, let alone specifically a long-press on a launcher icon. There is no requirement that there even be a launcher icon — the launcher does not have to use icons.
So, no, there is nothing that you can do for this that will offer this on each of the ~2.5 billion Android devices.
Note a device manufacturer's own launcher can do things with that manufacturer's own apps that it might not do with arbitrary third-party apps like yours or mine.
The functionality in possible
Then you should see the broadcast in Logcat.

Related

(Wear OS) How to detect a long press of physical button on a smartwatch while the app is running in background?

I'm a junior software developer and I need to develop an app for wear OS with the following key feature; to detect a long press of physical button on a smartwatch while the app is running in background. Is this even possible? If yes, I would truly appreciate for any links to samples and documentation.
thank you
As far as I know this is not possible. The multifunctional buttons can be mapped to custom actions, but only when an application is running in the foreground. Otherwise they are controlled by the system (to e.g. act as a shortcut to Google Pay).
Even if it was possible, your app would only work on some devices since not all models have a multifunctional button. The only button that is guaranteed to exist on all devices is the power button, and this one you can definitely not get any events from in your app.
You've probably seen this already but I'm attaching it in case it's helpful to someone:
Design guidelines plus recommended use cases and behavior can be found here
Implementation reference for the multifunctional buttons is here

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/

Programmatically launch default Android launcher and bring up application selection screen

Ok, on the surface I thought this would be fairly easy to do but it's proving challenging for me. All I would like to do is programmatically start the default Android launcher and bring up the apps selection screen. By "apps selection screen" I mean the screen with all the devices applications that is often built into Android, often it can be seen by hitting an "apps" button on a device, the icon associated with the button is often a series of rectangles... I don't actually know what this activity/app is called... so I hope I am articulating this properly.
I know how to start the launcher, the intent I am using looks like this:
Intent().setComponent(new ComponentName("com.android.launcher", "com.android.launcher.Launcher"))
This can be used to start the launcher, however I don't know how to bring up the apps screen. I have looked at the logs using logcat and find that I see nothing to indicate an activity/package/application name when I press the apps button on my device(s). Would anyone be able to shed any light on this for me?
I've been Googling this for quite awhile and haven't found anything I can use, this admittedly could be because I don't know the name of the functionality I am trying to trigger, but for the life of me I can't find that either! . If anyone could point me in the right direction I would really appreciate it. Thanks much.
I know how to start the launcher, the intent I am using looks like this:
There is no guarantee that com.android.launcher exists on any Android device, let alone that it is "the default Android launcher" for the user's configuration.
Would anyone be able to shed any light on this for me?
There are dozens, perhaps hundreds, of launcher implementations that come preinstalled on devices. There are hundreds, perhaps thousands, of launcher implementations that users can download from places like the Play Store. None are required to provide any means for a third-party app to directly drive to "the apps screen". Heck, some will not even have an "apps screen".
You can see the source code to com.android.launcher here. This particular launcher is ancient, and there is no separate activity for the "apps screen", let alone one that is exported for third-party use. The same holds true for com.android.launcher2.

Disabling the notification tray

A little background first. I'm developing an application for corporate devices running on the Android platform. It won't be distributed on the Play store and thus, is unavailable to the general public. The devices are owned by the company and its only purpose is to run this application. So accessing the home screen/notifications/application history/ app drawer are unnecessary and in fact we want to focus the user experience directly on this application.
The current problem I'm facing is preventing access to the notification tray. Simply making the application full screen is not a solution. We do actually need to see the status bar. It's the easiest way to provide network,gps and battery status information to the user.
So far my research has only turned up one solution, which is to go full screen (again, not a solution for this problem,I need the status bar to be visible). I know there's a number of lock screen apps that are able to do this so there must be a way. I just haven't found it yet.
I am not sure, but probably that you can't just lock notification bar from the application level. Android app is isolated from the Operating System and another apps, so it is not able to lock OS features.
Solution that came into my head is to make app fullscreen and create Your own status bar with battery level, current time and network status. It is not hard.
Another solution would be to prepare Your own Android distribution :)
Moreover probably You would like to override all buttons (home, back, search) so user is not able to leave your app.
Very likely is not going to be possible on a Stock device, you'd have to root and potentially install your own version of the OS to allow for this behavior. The system was purposefully made to disallow applications from having this type of behavior. The creators of the OS had the general public in mind as users, and they wanted to prevent applications from being able to "lock" the user out of portions of the device.
Much easier solution like #Jacek states is go full screen and make your own View to display whatever info that you do want from the Notifications bar, AFAIK there are public APIs to access all of that information.

how to keep track of which applications used most in android phone

HI ,
I need to keep track of installed applications which are used most and least in android device... can anyone help me how to do this programmatically in android...??
My question some thing like , I need to capture the event/Intent which will/may happen when the apllication is launched every time...(like BOOT_COMPLETED will be brodcasted when device booted).
This does not seem possible (unless the launcher/home screen or applications cooperate, e.g. through instrumentation: but that would be strange in production code!). See also this related question.
Edited to add: indiscriminate capture of application launch intents is not AFAIK permitted. Were Android to add such functionality, the security implications would be significant (particularly if interception or modification were allowed!). What you are describing could be (partially) achieved by replacing the home screen.
Some degree of usage information is collected already - from the launcher go to settings - about phone - battery use.
I think this resets every time you go on a charger, and don't know if its visible to ordinary apps.

Categories

Resources