From 6a3206462ab29390ec31fc62e75f71b037bab353 Mon Sep 17 00:00:00 2001 From: yongga Date: Wed, 13 Jan 2016 19:28:54 +0800 Subject: Gallery2: fix a crash when print a photo received from Bluetooth. An IllegalArgumentException occurs when getLocalPathFromUri(). catch this Exception and ensure print job work normally. Change-Id: I6c1f9912ac58ea23224c420da6327475a6935267 CRs-Fixed: 960251 --- .../gallery3d/app/AbstractGalleryActivity.java | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 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 b9007d57e..a7c54ee29 100644 --- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java +++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java @@ -366,23 +366,32 @@ public class AbstractGalleryActivity extends Activity implements GalleryContext if (uri == null) { return; } - String path = ImageLoader.getLocalPathFromUri(this, uri); - if (path != null) { - path = getLastPathSegment(path); - } else { - path = uri.getLastPathSegment(); - } + String printJobName = getLastPathSegment(uri); PrintHelper printer = new PrintHelper(this); try { - printer.printBitmap(path, uri); + printer.printBitmap(printJobName, uri); } catch (FileNotFoundException fnfe) { Log.e(TAG, "Error printing an image", fnfe); } } - private String getLastPathSegment(String path) { - if (path == null) return null; - Uri localUri = Uri.parse(path); + private String getLastPathSegment(Uri uri) { + String path = ""; + if (uri == null) return path; + try { + path = ImageLoader.getLocalPathFromUri(this, uri); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + + Uri localUri; + if (path != null) { + localUri = Uri.parse(path); + } else { + path = uri.getPath(); + localUri = uri; + } + String lastPathSegment = localUri.getLastPathSegment(); // uri.getLastPathSegment will return null if localUri contains -- cgit v1.2.3