diff options
Diffstat (limited to 'main/src/cgeo/geocaching/utils/ProcessUtils.java')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/ProcessUtils.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/utils/ProcessUtils.java b/main/src/cgeo/geocaching/utils/ProcessUtils.java index b566b79..1c05e84 100644 --- a/main/src/cgeo/geocaching/utils/ProcessUtils.java +++ b/main/src/cgeo/geocaching/utils/ProcessUtils.java @@ -3,8 +3,11 @@ package cgeo.geocaching.utils; import cgeo.geocaching.cgeoapplication; import android.content.Intent; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import java.util.List; + public final class ProcessUtils { private ProcessUtils() { @@ -12,9 +15,25 @@ public final class ProcessUtils { } public static boolean isInstalled(final String packageName) { - return getLaunchIntent(packageName) != null; + return (getLaunchIntent(packageName) != null) || hasPackageInstalled(packageName); + } + + /** + * 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); + for (final PackageInfo packageInfo : packs) { + if (packageName.equals(packageInfo.packageName)) { + return true; + } + } + return false; } + /** + * This will find applications, which can be launched. + */ public static Intent getLaunchIntent(final String packageName) { if (packageName == null) { return null; @@ -24,7 +43,7 @@ public final class ProcessUtils { // This can throw an exception where the exception type is only defined on API Level > 3 // therefore surround with try-catch return packageManager.getLaunchIntentForPackage(packageName); - } catch (Exception e) { + } catch (final Exception e) { return null; } } |
