Reputation: 319
I would like only to start some applications dynamically with the package name from the app i develop, i already tried this:
intent = new Intent(Intent.ACTION_VIEW);
component = new ComponentName(getApplicationContext(), myPrefs.getString("Combo1", null));
Log.i("LOG", myPrefs.getString("Combo1", null));
intent.setComponent(component);
and
intent = pm.getLaunchIntentForPackage(myPrefs.getString("Combo1", null));
startActivity(intent);
both works and several applications opens but for others i get this error.
11-29 21:42:08.723: E/AndroidRuntime(4719): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.lock/com.sec.android.app.phoneutil}; have you declared this activity in your AndroidManifest.xml?
I understand the error(that i need to add the app/activity in manifest), so i want to know if is a workaround to add dynamically activities to manifest, or there is a way to start dynamically an application without adding to the manifest that app/activity, or there is a permission that allow to open applications ?
From my research it seems impossible, but i want to know the opinion of an expert.
Thanx in advance.
Upvotes: 1
Views: 4443
Reputation: 799
Intent i = context.getPackageManager().getLaunchIntentForPackage("applications package name which you want to open"); context.startActivity(i);
Upvotes: 0
Reputation: 5183
If you are talking about launching other apps from yours, this is the code you need:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(packageName,mainActivity));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);
You can get the main activity like this:
Intent mIntent = ctx.getPackageManager().getLaunchIntentForPackage(packageName);
if (mIntent != null) {
if (mIntent.getComponent() != null) {
mainActivity = mIntent.getComponent().getClassName();
}
}
Upvotes: 7
Reputation: 1339
You can not start an activity (screen) without adding it to the manifest! ever!
Always add it!
Upvotes: 0