Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting activity from another application using only package name

Tags:

android

I want to start another application's Activity from my Activity, but all info, that I have is only the name of that application's package. I do following:

Intent intent = new Intent();
intent.setPackage(anotherApplicationPackageName);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);

As I understand correctly, using this API, Android will look for an Activity, which can handle this Intent inside the given package, but I always get ActivityNotFoundException.

The question is What am I doing wrong?

like image 845
teoREtik Avatar asked Dec 31 '25 14:12

teoREtik


2 Answers

    PackageManager  pmi = getPackageManager();
    Intent intent = null;

intent = pmi.getLaunchIntentForPackage(packageNameToLaunch);                    
if (intent != null){
    startActivity(intent);
}
like image 167
user462990 Avatar answered Jan 02 '26 03:01

user462990


You have to declare another activity's intent filter with category 'Intent.CATEGORY_DEFAULT' and create a custom action and call it using that category and action, setting the package in the intent only reduces its scope.

like image 39
Giohji Avatar answered Jan 02 '26 03:01

Giohji