Launching An External Shortcut - android

I'm trying to launch an external shortcut, What i have is only the activity path .
Here's what i did :
try {
view.getContext().startActivity(Intent.getIntentOld(List.getShortcutPath());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Log :
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=com.sonyericsson.music.ArtistShortcutActivity }
The Path I'm trying to launch :
com.sonyericsson.music.ArtistShortcutActivity
How to launch the shortcut ?

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
if you get permission denial error, then add android:exported XML attribute is true in the manifest for the activity you want to launch
Here com.example is the package name of the app your activity that you want to launch is in, and com.example.myexampleactivity the full name of the activity you want to launch
If the intended activity to launch is package private, then you wont be able to launch it from a foreign application activity. This is done for security reasons by Google

Related

Cannot start Settings$UserSettingsActivity

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".

Android Intent To Open Application Not Working

I am trying to open the Google Voice Search Application
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.google.android.voicesearch");
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
This does not launch the voice search application,
however if I use com.google.android.apps.maps as the package name then the Google Maps app is opened.
I don't understand why Voice Search is not opening, even though the package name is correct.
Solution
Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
startActivity(intent);
Please see
Launch Preinstalled App from activity (Google Voice Search) Android for more information on the solution.
Thank you.
As you can read here, getLaunchIntentForPackage (String packageName)
Return a "good" intent to launch a front-door activity in a package [...]
The current implementation will look first
for a main activity in the category CATEGORY_INFO, next for a main
activity in the category CATEGORY_LAUNCHER, or return null if neither
are found.
so, in the intent, the category will already be set. If you manually change it, probably you are breaking the intent, since the category could not be the correct one that the manager found.
so, just remove the line
i.addCategory(Intent.CATEGORY_LAUNCHER);

Starting a no launcher activity from another package

I try to start an activity from another package, but it has not LAUNCHER category
Intent i = new Intent();
i.setComponent(new ComponentName(maxVerPackageName, maxVerClassName));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
I faced the Exception: "An exception occurred: java.lang.SecurityException"
what's wrong, please help?
The other activity is enforcing a permission. So that only apps that have the permission or same uid can launch the activity.
Edit: If you have written other app
then add this attribute to the other activity which you are trying to launch
android:exported="true"

Starting an external activity, getting permission error

I'm trying to start the preferences activity in the native messenger client from my application. in AOSP Mms.apk does not have an intent filter setup on that activity. Regardless I'm trying to find a work around to launch the user into that screen.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(ComponentName.unflattenFromString("com.android.mms/com.android.mms.ui.MessagingPreferenceActivity"));
intent.addCategory("android.intent.category.LAUNCHER");
try {
startActivity(intent);
} catch (Exception e) {
AppUtils.alertError(this, error);
}
I'm receiving
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.mms/.ui.MessagingPreferenceActivity } from ProcessRecord{406e2738 674:com.handmark.genericapp/10034} (pid=674, uid=10034) requires null
Any thoughts?
What you want is not possible. That activity is not exported (at least in the source code showing in Google Code Search), so you cannot start it, except by rewriting the app as part of your own custom firmware.
Also, bear in mind that this app may or may not exist on any given device.

Interaction with Market app is causing window focus errors

I have a strange problem, I am wanting to launch to the marketplace from my app - am doing the following.
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"market://details?id=" + activity.getPackageName()));
try {
activity.startActivity(marketIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, "Could not launch market", Toast.LENGTH_LONG).show();
}
However when there the user can press Open again, when they do that I get :
08-22 15:18:37.510: INFO/ActivityManager(260): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.xyz.appname cmp=com.xyz.appname/.mainapp } from pid 22853
08-22 15:18:37.590: INFO/ActivityManager(260): Starting: Intent { cmp=com.xyz.appname/.secondactivity } from pid 25735
08-22 15:18:37.590: WARN/InputManagerService(260): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#2b49a938
and it never reopens the app , they just stuck there - hitting back does work.
Tracing the code the warning is coming from this in mainapp :
Intent tabActivity = new Intent();
tabActivity.setClass(this, secondactivity.class);
startActivity(tabActivity);
this.finish();
This definitely looks like an issue with how it is restarted - you're on the right track with that last bit of code.
This flag looks like what you need to tell Android to pull the existing activity off of the history stack and re-use it:
FLAG_ACTIVITY_SINGLE_TOP
Alternatively (if you want to restart rather than resume), maybe you could hint to Android to recycle the activity after you move on, by using this with your intent:
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

Categories

Resources