Reputation: 2491
I try to get a launch intent from a third party package from the PackageManager
. According to the documentation (http://developer.android.com/reference/android/content/pm/PackageManager.html#getLaunchIntentForPackage(java.lang.String)), it throws a PackageManager.NameNotFoundException
if the given package name cannot be found on the system and it returns null
if the package does not contain a launch activity.
When I try to catch the exception, I get a compilation error:
PackageManager manager = getPackageManager();
try{
Intent launchAppIntent = manager.getLaunchIntentForPackage("somePackageName");
//...
} catch (PackageManager.NameNotFoundException exception){
}
java: exception android.content.pm.PackageManager.NameNotFoundException is never thrown in body of corresponding try statement
I think that one possibility might be that the behavior of that method changed and it returns always null
instead of throwing an exception. But then, should I still wrap a try block around the call?
How should I proceed solving that issue?
I am currently building against Android 4.2.2.
Upvotes: 2
Views: 2902
Reputation: 579
The documentation is outdated.
"throws NameNotFoundException" has been removed from the method in Android 1.6 (API Level 4).
the current implementation in ApplicationPackageManager.java from Android 4.0 onwards does also not throw any exception.
You can safely remove the try catch.
P.S.: I know, the answer is a bit delayed, but I stumbled across the same, so why not share it here.
Upvotes: 6