Cannot start Settings$UserSettingsActivity - android

I have an application that displays all activities of all apps. It displayed the MultiUser Settings activity as
com.android.settings.Settings$UserSettingsActivity
Clicking on the above shortcut from this app launches the regular multiuser settings activity. But when I try to start the same activity from am or other ways like application intent, it fails to start.
I tried from adb,
am start com.android.settings.Settings$UserSettingsActivity
and the result log is
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=com.android.settings.Settings }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.android.settings.Settings }
I also tried to start it from application intent like,
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.settings.Settings", "com.android.settings.Settings.UserSettingsActivity"));
startActivity(intent);
Still it doesn't work.
My android device version is 5.1.1 lollipop.
Please help.

When you use the following command:
am start com.android.settings.Settings$UserSettingsActivity
adb takes com.android.settings.Settings$UserSettingsActivity as a package name and tries to find a launch Intent for that package, which fails (because com.android.settings.Settings$UserSettingsActivity is not a package name.
If you want to launch a specific component, the syntax is:
am start com.android.settings/com.android.settings.Settings$UserSettingsActivity
You need to specify the package name and the class name separated by "/"
When you do this in code:
intent.setComponent(new ComponentName("com.android.settings.Settings", "com.android.settings.Settings.UserSettingsActivity"));
you are passing the wrong arguments to the ComponentName constructor. The constructor takes 2 arguments: package name and class name. This needs to be like this:
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings$UserSettingsActivity"));
The package name is "com.android.settings" and the class name is "com.android.settings.Settings$UserSettingsActivity" which is an inner class of "com.android.settings.Settings".

Related

Cannot launch what 3 words intent

I am trying to open the what3words app using the documentation here
https://developer.what3words.com/tutorial/mobile-linking-to-the-what3words-app/
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("w3w://show?threewords=daring.lion.race"));
startActivityForResult(intent, INTENT_CODE);
but I keep getting this issue
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=w3w://show?threewords=daring.lion.race}
I am on my device and have google play and the what3words app installed on the device.
Try opening the app like this:
Intent intent = packageManager.getLaunchIntentForPackage("{w3w package name}");
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("w3w://show?threewords=daring.lion.race"));
startActivity(intent);
To get the package name look for it in adb:
adb shell pm list packages

Get continuous package name in service

I want to get continuously package name of launch app its working fine but when no one apps open then i want to get default launcher package name,So launcher package name get like below code:
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launcher_pkgname = localPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
Its working fine but in some device when i directly press home key then its get last open app package name not launcher package name
what can i do?
Help me please

How to update android app with hidden icon

I use this code for hiding icon:
PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName(this, MainActivity.class);
p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
It works fine, but when I try to update my application, I get this error:
Error while executing: am start -n "../..main.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=../.main.MainActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } }
Error type 3
Error: Activity class {../..main.MainActivity} does not exist.
Error while Launching activity
How can I hide icon and still available application update (without uninstall/install in a manual way)?
This is a design problem I think. You need to prevent MainActivity getting launched when it is disabled. If you are forced for some reason to start your MainActivty after updating, just enable your MainActivity first. You can set MainActivity enabled state to false in the Manifest and make it enabled whenever you need for example in onCreate method of the application class, in a service or in a broadcast receiver. Disabling MainActivity in the Manifest probably prevent it to be launched by default and might be the thing you need. It is all based on your need of how and when you want your MainActivity to get disabled and enabled again. For a final comment as you probably know an app doesn't need an activity - with action main or not - to get started.
just remove android.intent.category.LAUNCHER from the Activity and there will be no launcher icon - while it still can be launched, due to android.intent.action.MAIN. If you really need a launcher icon, which can be hidden & shown, simply add one proxy Activity, which has no other purpose than providing the launcher and then start the actual Activity... so that one still can start it directly, no matter if that proxy Activity had been disabled, whether or not.

Android call OEM activity by component name

On a Huwaie Ascend, when we walk through the settings menu:
Settings -> SD card & phone storage -> Software Upgrade -> SD card Upgrade
We are then brought to a screen where the user can upgrade.
And then using adb logcat we see this:
Starting activity: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.SystemUpgradeCheck }
We can use adb to simulate this by calling:
adb shell am start -n com.android.settings/.SystemUpgradeCheck
This is successful, and we see the screen.
However, when we try to call this from within an activity like this:
Intent i = new Intent(Intent.ACTION_MAIN);
i.setComponent(new ComponentName("com.android.settings", ".SystemUpgradeCheck"));
startActivity(i);
We get this error:
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.settings/.SystemUpgradeCheck}; have you declared this activity in your AndroidManifest.xml?
What can we do to overcome this? Am I calling the intent wrong?
Figured it out :)
Context foreignContext = createPackageContext("com.android.settings", Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
Class<?> yourClass = foreignContext.getClassLoader().loadClass("com.android.settings.SystemUpgradeCheck");
Intent intent = new Intent(foreignContext, yourClass);
startActivity(intent);

android - how to find the name of the main activity of an application?

For example, I want to start Gmail in code/command line, but I don't know its main activity name.
am start -n com.google.android.gm/.XXXXX
It's available through decompiling the apk, but it's difficult.
This can be found in the application's manifest.
The main activity is the activity with the intent-filter whose name is android.intent.action.MAIN.
You can plug your phone into the computer and look at the DDMS log, application launches are printed there, e.g:
05-11 09:19:15.725: INFO/ActivityManager(96): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x2000000 cmp=com.google.android.gm/.ConversationListActivity bnds=[125,410][235,540] } from pid 2457
So, com.google.android.gm/.ConversationListActivity, would seem like the right choice, at least, that's what the icon seems to launch.
Step1: Start "adb logcat" in command prompt.
Step2: Open the app (either in emulator or real device)
You don't need to know it's name, instead you should use implicit intent
and specify action along with type and some extras, for example
final Intent intent = new Intent();
intent.setType("message/rfc822");
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "Some subject");
System will search for components available to run this intent.
Just go to Android package n open Android Manifest File n check out this activity element
<activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</activity>

Categories

Resources