Call activity from an application from another android application

I want to trigger application activity from one action of another application. What am I doing here:

                Intent intent = new Intent();
                intent.setClassName("another_app_package_name", "another_app_package_name.class_name_in_that_package");

                startActivity(intent);

But my application stops throwing a NoActivityFound exception, saying that it cannot find the explicit activity class another_app_package_name.class_name_in_that_package.

I am missing something obvious. Can anybody help?

I am completely unfamiliar with the Android platform.

Thanx in advance.

+3
source share
3 answers
final Intent intent = new Intent();

ComponentName cName = new ComponentName
("package_name","package_name.class_name");

intent.setComponent(cName);         
startActivity(intent);

It will work. It worked for me!

+8
source

Something like this will work:

final Intent intent = new Intent();
intent.setComponent(new ComponentName("<package_name>", "<activity_class_name"));
context.startActivity(intent);

, , , exported . , - .

+1

-

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);

- . "com.htc.android.worldclock.WorldClockTabControl" - .

, :

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;
}

, .

0

Source: https://habr.com/ru/post/1778474/


All Articles