How to find the default applications in android? - android

I have an android application which lists the system and installed apps of a device.Also launch the selected one on click.It works fine.Now i want to disable listing of following applications.
Task Manager(which shows on long pressing home button)
Settings
These are the names used in Samsung Galaxy devices.I want to get the package name and launcher activity name of the application using for these purpose in Sony Ericson,Google phones,HTC and Samsung devices.
Also i want the package name of applications Camera,Email & Gmail using in these devices.
In short : I want to get the package name of these applications in the specified device because there are many apps can be use for a single purpose.For eg : ,There are many apps which can be use as a Task Manager, also we can change the default task manager and use a custom app for this purpose.So i don,t know which is used in users device.We can find the home launcher applications using Intent and ResolverActivity.Like this is there any way to get list of all applications which can be use as task manager,camera handling applications etc...?
Any help is much appreaciating.
Thanks in Advance

see task manager and settings dont have package name you can disable task manager by using this code
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.d("Focus debug", "Focus changed !");
if(!hasFocus) {
Log.d("Focus debug", "Lost focus !");
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
}
}
and settings goto by using
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
By using you can disale and enable. By last gmail,Email,camera you search by net and used in your code.
All the Best:)

Go to google play store and install package name viewer(https://play.google.com/store/apps/details?id=com.gijoon.pkgnameviewer&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5naWpvb24ucGtnbmFtZXZpZXdlciJd) you can see package name for each and every application.

Related

Set Default Android Launcher on Huawei devices?

My Goal is here is to set my app as default launcher on Huawei devices.
1 - Explanations:
1.1 - Current situation:
I am already able to:
Check if my app is the default launcher
Display the 'launcher picker' (with the 'use once' / 'always' choice)
This all works fine.. except on Huawei devices!
From my point of view, Huawei's Android flavor does not properly 'honor' the "ACTION_MANAGE_DEFAULT_APPS_SETTINGS" intent action contract.
// this displays the list of default apps on all tested devices, except on Huawei devices!
// instead, it does display apps permissions, app links and apps'advanced settings
intent.setAction(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
activity.startActivity(intent);
As a B Plan, I am able to display the 'Applications & Notifications' settings 'page' using this:
String packageName = "com.android.settings";
String className = "Settings$AppAndNotificationDashboardActivity";
intent.setClassName(packageName, packageName + "." + className);
activity.startActivity(intent);
So the user can navigate from there, pressing this sequence of menu items:
-> Advanced Parameters ( expandable menu item : not present on tablet, and not sure it's present on phone)
-> Default Apps
-> Default Launcher
This requires 2 or 3 steps that I would like to avoid.
1.2 - This can be improved!
I found out that when the "-> Default Apps" menu item is selected, a (com.android.settings, .SubSettings) Intent (with extra) is launched but I was not able to make this works (permission denial).
But I installed Nova Launcher and it turns out it's able to display the "-> Default Apps" settings page on Huawei devices!
So the user land on a page where she/he only has to tap on "-> Default Launcher" then choose a default launcher: much easier.
2 - Questions:
As I think it's just not possible to display the 'Lancher Picker' on Huawei devices, here is my question:
How can I display the "-> Default Apps" settings page (image down here) on Huawei devices (like Nova Launcher does)?
Are they using another intent action on Huawei devices?
Thanks beforehand your help.
Yes on Huawei devices, Nova uses a different intent to open to the correct screen. I likely found this by using apktool on the Settings.apk pulled from a Huawei device and looking at the AndroidManifest.
Note that "com.android" is always a code smell as it means it's not part of the public API. Also this isn't even really "com.android" as it doesn't exist on AOSP and com.android.settings.PREFERRED_SETTINGS is purely a Huawei invention. It's very likely that some Huawei devices won't have this at all. It's also possible that in the future this intent might continue to work but not do what it currently does. So handle it carefully.
/* Some Huawei devices don't let us reset normally, handle it by opening preferred apps */
Intent preferredApps = new Intent("com.android.settings.PREFERRED_SETTINGS");
preferredApps.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (pm.resolveActivity(preferredApps, 0) != null) {
context.startActivity(preferredApps);
} else {
...
}
In fact, the accepted answer is not 100% correct, because it opens a general default apps chooser activity.
It works, but it's better to bring user right to the launcher chooser activity — it's com.google.android.permissioncontroller/com.android.packageinstaller.role.ui.HomeSettingsActivity (at least for the Android 10 Huawei Honors).
So, the correct code snippet is:
Intent()
.apply {
component = ComponentName("com.google.android.permissioncontroller", "com.android.packageinstaller.role.ui.HomeSettingsActivity")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
}
.takeIf {
packageManager.resolveActivity(it, 0) != null
}
?.let(context::startActivity)

android open battery settings programically

I'm looking for a way to open the battery settings screen from an android app.
So far I found the two intents :
Intent.ACTION_POWER_USAGE_SUMMARY
Settings.ACTION_BATTERY_SAVER_SETTINGS
but none of them open this screen.
I was wondering if anyone knows of such a way. It sounds strange that an intent for something so simple doesn't exist
Settings.ACTION_BATTERY_SAVER_SETTINGS on "plain" Android versions will show the settings page you want to show.
Intent.ACTION_POWER_USAGE_SUMMARY will lead to the overview page showing the battery consumption.
Some manufactures such as Samsung build their own implementation over the system one, e.g. in this the "Battery" page. On Samsung devices, you can call this by calling the SmartManager interface directly. An code example:
if (Build.MANUFACTURER == "samsung") {
val intent = Intent()
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
intent.component = ComponentName("com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity")
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
intent.component = ComponentName("com.samsung.android.sm", "com.samsung.android.sm.ui.battery.BatteryActivity")
}
try {
activity?.startActivity(intent);
} catch (ex: ActivityNotFoundException) {
// Fallback to global settings
startActivity(Intent(Settings.ACTION_SETTINGS))
}
} else {
startActivity(Intent(Settings.ACTION_BATTERY_SAVER_SETTINGS))
}
It can be the case that you need additional cases for Huawei or Xiaomi as well.
Huawei can be "com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"...
...and the MIU based ones "com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"
I know this is quite old. But a trick I use is going to the appropriate settings screen in the device settings and then while connected to the phone run:
adb shell
dumpsys window windows | grep -E 'mCurrentFocus'
This returns the package name and Activity name currently in focus.
Using that I can check in code if the intent is callable. If it is, I launch it. If it isnt, I might have better luck with a different screen that is near by or explain to the user he needs to do something manually etc... Obviously the more devices you have, the more Intents you can create and check at run time. Im sure there is a list of Intents for different devices online.

How to enable Android Open Application voice interaction

According to the system voice command docs, you can open an application with a voice command. e.g. OK Google - open foobar. Also according to the docs, this Works by default; no specific intent.
In my sample development app, this isn't working. I've tried adding a few combinations of action and category permutations to the intent-filter, but no luck so far.
I'm targeting a minimum SDK of 23, testing on a device with 6.0.1.
Should this work, and if so, what are the changes to a new empty activity project I need to enable it?
As far as I am aware, Google simply iterates over a list of installed applications and opens the corresponding application if it finds an exact match.
To test this, use the following Intent
final String PACKAGE_NAME_GOOGLE_NOW = "com.google.android.googlequicksearchbox";
final String GOOGLE_NOW_SEARCH_ACTIVITY = ".SearchActivity";
final String APP_NAME = "Open " +getString(R.string.app_name);
final Intent startMyAppIntent = new Intent(Intent.ACTION_WEB_SEARCH);
startMyAppIntent.setComponent(new ComponentName(PACKAGE_NAME_GOOGLE_NOW,
PACKAGE_NAME_GOOGLE_NOW + GOOGLE_NOW_SEARCH_ACTIVITY));
startMyAppIntent.putExtra(SearchManager.QUERY, APP_NAME);
startMyAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(startMyAppIntent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
}
If this opens your application, then it is simply a case of the phonetics of your application name, or how Google interprets your pronunciation of it.
I do think that there should be an option to add a 'phonetic app label' to the application's manifest (or some other globally available configuration file), so Google could open your application if the unique name is not common enough to generate a voice search result.
If this doesn't open your application, check that you are correctly defining your application name in the manifest as follows:
<application
android:label="#string/app_name"

Set default service for 'Other' category | HCE

If there are multiple services(apps) capable of NFC HCE payments are installed. Those application services are visible under settings NFC Tap and Pay.
There are two AID group defined, one for payment and second for other cateogy.
How to programmatically change your application to be the default 'other category'service if it's not?
Below is the code that I'm executing, but dialog is not invoked to select running application for 'other category'. However for 'payment category' dialog is opened successfully. Below is the code:
CardEmulation cardEmulation = CardEmulation.getInstance(NfcAdapter.getDefaultAdapter(this));
boolean isDefaultCategorySelected = cardEmulation.isDefaultServiceForAid(new ComponentName(this, MyOffHostApduService.class), "F4100000040001");
if(!isDefaultCategorySelected(CardEmulation.CATEGORY_OTHER)){
Intent intent = new Intent(CardEmulation.ACTION_CHANGE_DEFAULT);
intent.putExtra(CardEmulation.EXTRA_CATEGORY, CardEmulation.CATEGORY_OTHER);
intent.putExtra(CardEmulation.EXTRA_SERVICE_COMPONENT, new ComponentName(this, MyOffHostApduService.class));
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_TRANSIT_SERVICE);
return;
}
You can't.
Global defaults are currently only supported for CATEGORY_PAYMENT. The resolution strategy for CATEGORY_OTHER is always set to SELECTION_MODE_ASK_IF_CONFLICT. Hence, your application must either be the only application that registers a certain AID group in CATEGORY_OTHER or Android will ask the user upon a transaction which app should be used.
You may be able to use CardEmulation.setPreferredService() though in order to set your HCE service as the default while one of your activities is in the foreground.

Unknown sources settings android

The issue is that I need to install an apk(non market app) and for this, the user need to activate the unknown source setting, so i send him (if he didn't have it activated) to the settings so he can turn on the option, the issue is that i tested it in different phones and in samsung that option is on applications while in htcs phones is on security. i want send the user to that option but i don't know how to do it
I read about this and no one knows exactly how to do it
this is my code
int canInstallFromOtherSources = Settings.Secure.getInt(ctx2,Settings.Secure.INSTALL_NON_MARKET_APPS);
if(canInstallFromOtherSources == 0)
{
Intent intentSettings = new Intent();
intentSettings.setAction(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intentSettings);
}
You can do it with the following line (changing to the corresponding action):
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), REQUEST_CODE_ENABLE_LOCATION_PROVIDERS);
Check Android Settings documentation.
I think you should use ACTION_SECURITY_SETTINGS and one of ACTION_APPLICATION_SETTINGS or ACTION_APPLICATION_DEVELOPMENT_SETTINGS.
And here (line 304), you've got a working example of one of my apps: Tureame

Categories

Resources