diff options
Diffstat (limited to 'main/src/cgeo/geocaching/utils/ProcessUtils.java')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/ProcessUtils.java | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/utils/ProcessUtils.java b/main/src/cgeo/geocaching/utils/ProcessUtils.java index 3345ff1..d80674b 100644 --- a/main/src/cgeo/geocaching/utils/ProcessUtils.java +++ b/main/src/cgeo/geocaching/utils/ProcessUtils.java @@ -1,13 +1,14 @@ package cgeo.geocaching.utils; -import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.CgeoApplication; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.net.Uri; import java.util.List; @@ -43,7 +44,7 @@ public final class ProcessUtils { * This will find installed applications even without launch intent (e.g. the streetview plugin). */ private static boolean hasPackageInstalled(final String packageName) { - final List<PackageInfo> packs = cgeoapplication.getInstance().getPackageManager().getInstalledPackages(0); + final List<PackageInfo> packs = CgeoApplication.getInstance().getPackageManager().getInstalledPackages(0); for (final PackageInfo packageInfo : packs) { if (packageName.equals(packageInfo.packageName)) { return true; @@ -59,7 +60,7 @@ public final class ProcessUtils { if (packageName == null) { return null; } - final PackageManager packageManager = cgeoapplication.getInstance().getPackageManager(); + final PackageManager packageManager = CgeoApplication.getInstance().getPackageManager(); try { // This can throw an exception where the exception type is only defined on API Level > 3 // therefore surround with try-catch @@ -70,10 +71,34 @@ public final class ProcessUtils { } public static boolean isIntentAvailable(final String intent) { - final PackageManager packageManager = cgeoapplication.getInstance().getPackageManager(); - final List<ResolveInfo> list = packageManager.queryIntentActivities( - new Intent(intent), PackageManager.MATCH_DEFAULT_ONLY); + return isIntentAvailable(intent, null); + } + /** + * Indicates whether the specified action can be used as an intent. This + * method queries the package manager for installed packages that can + * respond to an intent with the specified action. If no suitable package is + * found, this method returns false. + * + * @param action + * The Intent action to check for availability. + * @param uri + * The Intent URI to check for availability. + * + * @return True if an Intent with the specified action can be sent and + * responded to, false otherwise. + */ + public static boolean isIntentAvailable(final String action, final Uri uri) { + final PackageManager packageManager = CgeoApplication.getInstance().getPackageManager(); + final Intent intent; + if (uri == null) { + intent = new Intent(action); + } else { + intent = new Intent(action, uri); + } + final List<ResolveInfo> list = packageManager.queryIntentActivities(intent, + PackageManager.MATCH_DEFAULT_ONLY); return CollectionUtils.isNotEmpty(list); } + } |
