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);
Related
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
Okay, I think I'm missing something here but can't seem to find a way around it :\
So this is my scenario, I have two apps, A and B. A Opens a B with the following intent:
PackageManager pm = getPackageManager();
Intent n = pm.getLaunchIntentForPackage(currAppInfo.getName());
n.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(n);
(currAppInfo is a custom object and getName returns the package name.)
Anyway, B is installing APKs. A receives the package installed broadcast and should be now moved back to front, how ever if I'm starting app A with an intent
Intent serviceIntent = new Intent();
serviceIntent.setClass(context, MainActivity.class);
serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceIntent);
Instead of seeing A's mainActivity screen all I see is B's main activity screen.
Why is that? Is it the way I open the apps with the intents or am I missing something more basic here?
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".
I'm trying to allow a user to supply a class name and then launch the Activity but I keep getting an error stating:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.intel.ave.androidclient/com.android.vending}; have you declared this Activity in your AndroidManifest.xml?
I haven't placed it in my Manifest as I won't know what the user wants at runtime.
//package_name = input from the user
//MyContext = the activity context
Intent newprocess = new Intent(Intent.ACTION_MAIN);
newprocess.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newprocess.setClassName(MyContext, package_name);
MyContext.startActivity(newprocess );
Starting an external activity with an intent is a bit different than starting within your app. See calling activity from external Activity. Quoting from there, you would use this instead
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.the.other.app");
startActivity(intent);
FLAG_ACTIVITY_NO_HISTORY is not working for starting android settings activity (android.provider.Settings.ACTION_SETTINGS)
I have an activity from which I start Android Settings Window (android.provider.Settings.ACTION_SETTINGS). I do it like that:
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
activityContext.startActivity(intent);
It usually works. However, when I follow these steps:
1) launch settings from my activity
2) go further (i.e. Wireless & networks),
3) press home, etc
3) launch my activity again
4) launch settings from my activity
5) then 'Wireless & networks' screen appears instead of main android settings activity!
I also tried:
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activityContext.startActivity(intent);
But it's not working either. Do you know what might be the problem? I wanted to add that flag FLAG_ACTIVITY_NO_HISTORY works for my internal activities.
Try adding the flag Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED to the intent.