From c10a326b5862e3769851fe4349eaa5a18bd17d31 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Fri, 13 Sep 2013 00:22:31 +0200 Subject: Gallery2: Fix showOnMap method If the context is ProxyLauncher, showOnMap will make crash the Gallery app if GoogleMaps not exists, because the double call to startActivity. Just query the intent before call the startActivity method. Change-Id: I2e2637626d9f81780f48625bef52e861180e002c Signed-off-by: Jorge Ruesga --- src/com/android/gallery3d/util/GalleryUtils.java | 48 +++++++++++++++--------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/com/android/gallery3d/util/GalleryUtils.java b/src/com/android/gallery3d/util/GalleryUtils.java index 7b824275c..6a216cc7f 100644 --- a/src/com/android/gallery3d/util/GalleryUtils.java +++ b/src/com/android/gallery3d/util/GalleryUtils.java @@ -271,25 +271,37 @@ public class GalleryUtils { } public static void showOnMap(Context context, double latitude, double longitude) { - try { - // We don't use "geo:latitude,longitude" because it only centers - // the MapView to the specified location, but we need a marker - // for further operations (routing to/from). - // The q=(lat, lng) syntax is suggested by geo-team. - String uri = formatLatitudeLongitude("http://maps.google.com/maps?f=q&q=(%f,%f)", - latitude, longitude); - ComponentName compName = new ComponentName(MAPS_PACKAGE_NAME, - MAPS_CLASS_NAME); - Intent mapsIntent = new Intent(Intent.ACTION_VIEW, - Uri.parse(uri)).setComponent(compName); - context.startActivity(mapsIntent); - } catch (ActivityNotFoundException e) { - // Use the "geo intent" if no GMM is installed - Log.e(TAG, "GMM activity not found!", e); - String url = formatLatitudeLongitude("geo:%f,%f", latitude, longitude); - Intent mapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - context.startActivity(mapsIntent); + // We use isIntentResolved here, because startActivity could derive in ProxyLauncher + // invocation, which makes an startActivity, and if the intent not exists we get a FC. + + // 1.- GMM with MapView + // We don't use "geo:latitude,longitude" because it only centers + // the MapView to the specified location, but we need a marker + // for further operations (routing to/from). + // The q=(lat, lng) syntax is suggested by geo-team. + ComponentName gmmCompName = new ComponentName(MAPS_PACKAGE_NAME, MAPS_CLASS_NAME); + String gmmUri = formatLatitudeLongitude("http://maps.google.com/maps?f=q&q=(%f,%f)", + 0.0d, 0.0d); + Intent gmmIntent = new Intent(); + gmmIntent.setComponent(gmmCompName); + gmmIntent.setData(Uri.parse(gmmUri)); + gmmIntent.setAction(Intent.ACTION_VIEW); + if (isIntentResolved(context, gmmIntent)) { + context.startActivity(gmmIntent); + return; } + + // 2.- Geolocation content provider + Log.w(TAG, "GMM activity not found! Trying with geo scheme"); + String geoUri = formatLatitudeLongitude("geo:%f,%f", 0.0d, 0.0d); + Intent geoIntent = new Intent(); + geoIntent.setData(Uri.parse(geoUri)); + geoIntent.setAction(Intent.ACTION_VIEW); + if (isIntentResolved(context, geoIntent)) { + context.startActivity(geoIntent); + } + + // No maps. Why isGeolocationViewAvailable method not working? } public static boolean isGeolocationViewAvailable(Context context) { -- cgit v1.2.3