I want to call an application's activity from within an activity of another application. What I'm doing here is:
Intent intent = new Intent();
intent.setClassName("another_app_package_name", "another_app_package_name.class_name_in_that_package");
startActivity(intent);
But my application is quitting throwing NoActivityFound exception saying that unable to find explicit activity class another_app_package_name.class_name_in_that_package.
I'm missing something obvious. I'm fair开发者_C百科ly new to Android platform.
final Intent intent = new Intent();
ComponentName cName = new ComponentName
("package_name","package_name.class_name");
intent.setComponent(cName);
startActivity(intent);
This will work. It worked for me!
Something like this will work:
final Intent intent = new Intent();
intent.setComponent(new ComponentName("<package_name>", "<activity_class_name"));
context.startActivity(intent);
But the application that owns the activity you want to start must declare the activity with "exported" in its manifest. The default for that option is false if the activity doesn't declare any intent filters.
Try something like
final Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN); //might not be necessary
i.setClassName("com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl");
startActivity(i);
The class name - e.g. "com.htc.android.worldclock.WorldClockTabControl" - must be fully qualified.
If this isn't working, try calling the following method with your intent's class name string:
public static boolean isIntentAvailable(final Context context,
final String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
final List<ResolveInfo> list = packageManager.queryIntentActivities(
intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
and see what it returns.
精彩评论