neha
neha

Reputation: 6377

Calling an activity from an application from another application android

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 fairly new to Android platform.

Upvotes: 3

Views: 7976

Answers (3)

tarun_tenniso
tarun_tenniso

Reputation: 214

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!

Upvotes: 8

Jerry Brady
Jerry Brady

Reputation: 3080

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.

Upvotes: 1

Jon Willis
Jon Willis

Reputation: 7024

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.

Upvotes: 0

Related Questions