From 7026db4ab23bb71aa8f356eae8d5ba6ba058f207 Mon Sep 17 00:00:00 2001 From: yongga Date: Thu, 7 Jan 2016 15:15:54 +0800 Subject: Gallery2: fix a crash when print a photo. fix a crash when print a photo whose file name contains ':' character. Change-Id: Ib9ace0cca50c65dd7c42015e85a309ac2cf361f5 CRs-Fixed: 948075 --- .../android/gallery3d/app/AbstractGalleryActivity.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java index 915fc948a..b9007d57e 100644 --- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java +++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java @@ -368,8 +368,7 @@ public class AbstractGalleryActivity extends Activity implements GalleryContext } String path = ImageLoader.getLocalPathFromUri(this, uri); if (path != null) { - Uri localUri = Uri.parse(path); - path = localUri.getLastPathSegment(); + path = getLastPathSegment(path); } else { path = uri.getLastPathSegment(); } @@ -381,6 +380,21 @@ public class AbstractGalleryActivity extends Activity implements GalleryContext } } + private String getLastPathSegment(String path) { + if (path == null) return null; + Uri localUri = Uri.parse(path); + String lastPathSegment = localUri.getLastPathSegment(); + + // uri.getLastPathSegment will return null if localUri contains + // spacial characters such as ':', so use other way to get it. + if (lastPathSegment == null) { + // use substring to get last path segment. + int indexOfLastPathSegment = path.lastIndexOf("/") + 1; + lastPathSegment = path.substring(indexOfLastPathSegment, path.length()); + } + return lastPathSegment; + } + public Toolbar getToolbar() { return mToolbar; } -- cgit v1.2.3