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?
PackageManager pmi = getPackageManager();
Intent intent = null;
intent = pmi.getLaunchIntentForPackage(packageNameToLaunch);
if (intent != null){
startActivity(intent);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With