diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-06-21 18:40:55 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-06-21 18:40:55 +0200 |
| commit | c9674378346d06000b0a66b919bc57c7729dd2bd (patch) | |
| tree | 76b890e4bb079d13fb92f11b5cd8caada2f3864c /main/src/cgeo/geocaching/utils | |
| parent | d5cfd39dce286d94b84a2acc91e962108be25819 (diff) | |
| download | cgeo-c9674378346d06000b0a66b919bc57c7729dd2bd.zip cgeo-c9674378346d06000b0a66b919bc57c7729dd2bd.tar.gz cgeo-c9674378346d06000b0a66b919bc57c7729dd2bd.tar.bz2 | |
new: only show streetview menu if available
Diffstat (limited to 'main/src/cgeo/geocaching/utils')
| -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; } } |
