I have an app idea and have a simple question, can I change the behaviour of wifi item on quick settings menu on Android? I want it to redirect to my app. Is this possible?
Not generally.
You can examine Logcat and see what happens when the user taps that tile. If the tile starts an activity (probably yes) and the Intent that is used is implicit (action but no ComponentName or package), then you could create an activity with a matching <intent-filter>. The user would be able to choose to launch your activity instead of the standard one.
However, bear in mind that there is no requirement that the Intent that the tile uses would be the same across Android versions and device manufacturers.
Related
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.
My security company's mobile app (CPI inTouch) allows me to create "scenes" which trigger multiple actions at the same time with a press of one button (e.g. disarming the alarm and unlocking the smart lock on my door). I've also added shortcuts to each of the scenes on my home screen (on my Samsung Galaxy Note9, if that's relevant) so I can launch a scene via the shortcut without having to go into the app itself.
However, having just purchased Tasker, I'd like to trigger the shortcut (or the activity in the app itself) programmatically in a Tasker profile or some other automation app. I've tried plenty of apps that allow you to trigger a shortcut based on an event, but none have these particular shortcuts in the list of available ones. I read that I should be able to use a Send Intent task in Tasker to do this, but I don't know what the intent string would be or where to find it.
In case you can suggest a different way to achieve this, the main use case so far is to have my alarm system automatically disarmed when my phone's morning alarm goes off.
First thing to check would be...
create new task to Launch App,
find your CPI app and if it has a "+" in top right corner of app icon you can long press it to reveal a list of activities.
if your app does not offer those options...
The Tasker dev also has a group of plugins under the AutoApps group, there is one called AutoShortcut that launches shortcuts.
edit: there are apps such as APK Analyzer that can show you the activities and services inside an app and whether or not they can receive intents from external apps.
The iOS OS provides this back button on the top of an app that was opened via custom URL schemes. This button generally displays the name of the app that launched the custom URL scheme. This could be seen in the screenshot, "Return to Search". Search is the app that opened the app in foreground now.
I was wondering if we could customise the android action bar, to have a similar effect when my app is opened thorough custom URL intents.
NOTE - I know iOS do not have a back button, and hence this was developed. But displaying the app name, makes it explicit that my app was opened via URL intent by this app. It provides higher visibility to the users.
I was wondering if we could customise the android action bar, to have a similar effect when my app is opened thorough custom URL intents.
No, insofar as you have no way of knowing who started your activity.
The is no way of doing it automatically, but:
Android API lvl 22 introduced a new method getReferrer() to return information about who launched this activity.
By default, it will return a android-app: referrer URI.
For instance, Chrome beta will use android-app//:com.chrome.beta as referrer when launching an app.
You could therefore use this value (it might not be 100% trusted) and query the package manager to get the application label.
You can collect some data that manages user experience, but only in your own environment. For example N apps that interact with each other. If you think closely you will see that knowing who wakes your app up doesn't make sense since the caller can use a broadcast, for instance.
Once my Home Screen app 'ABC' is installed on the device & when the user presses the Home Button, he is prompted with the Default Action Android dialog to choose between the Default Home & my ABC app.
My use case is to keep on prompting the user - a bit infrequently though, with this Default Action dialog till he selects my App as default.
How we can default action in android ?
Before ICS (and maybe Honeycomb), you could set the preferred activity using the PackageManager#addPreferredActivity method.
But as stated in the documentation :
This is a protected API that should not have been available to third party applications. It is the platform's responsibility for assigning preferred activities and this can not be directly modified.
This indeed could be used by Malware to change what applications the launcher icons start. I would really advise you not to use it and instead let your users the choice to make themselves your launcher their default launcher.
call the below intent when you need to see the 'launcher' selection dialog, unless one of the launcher apps is set as default
Intent homeIntent = new Intent("android.intent.action.MAIN");
homeIntent.addCategory("android.intent.category.HOME");
startActivity(homeIntent);
We're trying to provide an application to the mentally and physically handicapped daughter of my neighbor that let's her use an Android tablet as a Talker, i.e., she presses a few big buttons and the devices generates speech. The application is basically a WebView and an additional object in Javascript used to perform and control the speech generation, plus some logic to handle the orientation changes. Html files are generated offline for her specific layout of the talking items. We've also added some music playing and picture viewing facilities to make the device more appealing to her.
Problem is that the home button brings her back into the madness of the Android launcher screen, and that on the test device (Archos 70) the home button is not a physical button but rather shown on the touch screen itself, making it too easy to accidentally hit it.
So I'd like to return to the Android launcher only by pressing a sequence home, back, home with no other action in between.
Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?
The only clue I found so far is Overriding Home button for a Car Home replacement app, but this is rated -1 and reported to work in the emulator only. Also I doubt if I could completely abandon the original launcher, as otherwise there is no access anymore to e.g. the USB mass device control to allow new HTML files to be downloaded, the application to be killed and restarted, and so forth.
I'm willing to go for a kludge as well. Maybe a background service could be started that would bring the application to the front again as necessary?
The Home button cannot be overriden. You can write an application that responds to the home intent (that's what a launcher does) but that's all.
Can I achieve this by making my application itself the launcher? How can I then get back to the original launcher upon the home, back, home sequence? It seems that this goes deep into the innards of Android, huh?
Yes. Not too deep into the
innards. You can manually start a launcher by specifying the component, note that this may vary from device to device and user to user, if you're just using this privately you could hard code it, but if you release it you must allow the user to specify their real home app.
/* This should come from a preference that let's the user select an activity that can handle the HOME intent */
String packageName = "com.android.launcher";
String packageClass = "com.android.launcher2.Launcher";
Intent home_intent = new Intent(Intent.ACTION_MAIN);
home_intent.addCategory(Intent.CATEGORY_HOME);
home_intent.setComponent(new ComponentName(packageName, packageClass));
home_intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
/* Here you should catch the exception when the launcher has been uninstalled, and let the user save themselves by opening the Market or an app list or something. Users sometimes use root apps to uninstall the system launcher, so your fake launcher is all that is left. Might as well give the poor user a hand. */
startActivity(home_intent);
Detecting home/back/home is a bit awkard because home won't come as a onKeyEvent but instead as a new intent. Simply long-pressing the back button then display a prompt is probably a safe/good approach.