diff options
author | kaiyiz <kaiyiz@codeaurora.org> | 2014-11-27 10:35:11 +0800 |
---|---|---|
committer | cretin45 <cretin45@gmail.com> | 2014-12-15 14:57:47 -0800 |
commit | 04e41ae3b855fca7669f5742a3e85ceab0274077 (patch) | |
tree | f7288e9173e44576c2de63242ce47ec40008d71e | |
parent | c606d953a8d6b7a8b7957c8652a93e8d8a518925 (diff) | |
download | android_packages_apps_Gallery2-04e41ae3b855fca7669f5742a3e85ceab0274077.tar.gz android_packages_apps_Gallery2-04e41ae3b855fca7669f5742a3e85ceab0274077.tar.bz2 android_packages_apps_Gallery2-04e41ae3b855fca7669f5742a3e85ceab0274077.zip |
Gallery2: fix app crash when there is no map app
ActivityNotFoundException happened after click showOnMap menu when
there is no map app.
Catch the Exception to avoid app crash.
CRs-Fixed: 753928
Change-Id: I7d811e4a636bed22935fcc050d97559ace44eb31
-rw-r--r-- | res/values-zh-rCN/strings.xml | 3 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/com/android/gallery3d/util/GalleryUtils.java | 21 |
3 files changed, 24 insertions, 3 deletions
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index 2144e99d5..4de380467 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -426,6 +426,9 @@ <string name="remember_location_prompt" msgid="724592331305808098">"为您的照片和视频标明拍摄地点。\n\n其他应用在查看您保存的照片和视频时将可以使用这些信息。"</string> <string name="remember_location_no" msgid="7541394381714894896">"不用了"</string> <string name="remember_location_yes" msgid="862884269285964180">"好"</string> + <!-- The message is shown in toast when click showOnMap Menu and there is no map app --> + <string name="map_activity_not_found_err">没有地图应用显示地理位置信息</string> + <string name="menu_camera" msgid="3476709832879398998">"相机"</string> <string name="menu_search" msgid="7580008232297437190">"搜索"</string> <string name="tab_photos" msgid="9110813680630313419">"照片"</string> diff --git a/res/values/strings.xml b/res/values/strings.xml index 405b0b3fc..7f347a1d6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1104,6 +1104,9 @@ CHAR LIMIT = NONE] --> <!-- Positive answer for first run dialog asking if the user wants to remember photo locations [CHAR LIMIT = 20] --> <string name="remember_location_yes">Yes</string> + <!-- The message is shown in toast when click showOnMap Menu and there is no map app --> + <string name="map_activity_not_found_err">There is no map app for show location.</string> + <!-- Menu item to launch the camera app [CHAR LIMIT=25] --> <string name="menu_camera">Camera</string> <!-- Menu item to search for photos [CHAR LIMIT=25] --> diff --git a/src/com/android/gallery3d/util/GalleryUtils.java b/src/com/android/gallery3d/util/GalleryUtils.java index 8fb926c0b..8e4ebb714 100644 --- a/src/com/android/gallery3d/util/GalleryUtils.java +++ b/src/com/android/gallery3d/util/GalleryUtils.java @@ -17,6 +17,7 @@ package com.android.gallery3d.util; import android.annotation.TargetApi; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; @@ -35,6 +36,7 @@ import android.provider.MediaStore; import android.util.DisplayMetrics; import android.util.Log; import android.view.WindowManager; +import android.widget.Toast; import com.android.gallery3d.R; import com.android.gallery3d.app.GalleryActivity; @@ -275,7 +277,7 @@ public class GalleryUtils { return String.format(Locale.ENGLISH, format, latitude, longitude); } - public static void showOnMap(Context context, double latitude, double longitude) { + public static void showOnMap(final 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 @@ -292,8 +294,21 @@ public class GalleryUtils { // 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); + try { + Intent mapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + context.startActivity(mapsIntent); + } catch (ActivityNotFoundException ex) { + Log.e(TAG, "Map view activity not found! url = " + url, ex); + ((Activity)context).runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(context, + context.getString(R.string.map_activity_not_found_err), + Toast.LENGTH_SHORT).show(); + } + }); + + } } } |