aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/apps/AbstractApp.java4
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java8
-rw-r--r--main/src/cgeo/geocaching/utils/ProcessUtils.java23
3 files changed, 30 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/apps/AbstractApp.java b/main/src/cgeo/geocaching/apps/AbstractApp.java
index ef56f87..f3715f3 100644
--- a/main/src/cgeo/geocaching/apps/AbstractApp.java
+++ b/main/src/cgeo/geocaching/apps/AbstractApp.java
@@ -5,6 +5,8 @@ import cgeo.geocaching.MainActivity;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.utils.ProcessUtils;
+import org.apache.commons.lang3.StringUtils;
+
import android.content.Intent;
public abstract class AbstractApp implements App {
@@ -26,7 +28,7 @@ public abstract class AbstractApp implements App {
@Override
public boolean isInstalled() {
- if (ProcessUtils.isInstalled(packageName)) {
+ if (StringUtils.isNotEmpty(packageName) && ProcessUtils.isInstalled(packageName)) {
return true;
}
return MainActivity.isIntentAvailable(intent);
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java b/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java
index 012b94f..e2c0828 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/StreetviewApp.java
@@ -4,6 +4,7 @@ import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.utils.ProcessUtils;
import android.app.Activity;
import android.content.ActivityNotFoundException;
@@ -12,13 +13,16 @@ import android.net.Uri;
class StreetviewApp extends AbstractPointNavigationApp {
+ private static final String PACKAGE_NAME_STREET_VIEW = "com.google.android.street";
+ private static final boolean INSTALLED = ProcessUtils.isInstalled(PACKAGE_NAME_STREET_VIEW);
+
StreetviewApp() {
super(getString(R.string.cache_menu_streetview), null);
}
@Override
public boolean isInstalled() {
- return true;
+ return INSTALLED;
}
@Override
@@ -26,7 +30,7 @@ class StreetviewApp extends AbstractPointNavigationApp {
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("google.streetview:cbll=" + point.getLatitude() + "," + point.getLongitude())));
- } catch (ActivityNotFoundException e) {
+ } catch (final ActivityNotFoundException e) {
ActivityMixin.showToast(activity, cgeoapplication.getInstance().getString(R.string.err_application_no));
}
}
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;
}
}