From 543c4198d8bd5f4d8ecd02a778d4b9009062cd80 Mon Sep 17 00:00:00 2001 From: Dominik Pesch Date: Wed, 4 Jun 2014 22:16:32 +0200 Subject: [PATCH] CB-6875 android: Handle exception when SDCard is not mounted close #29 --- src/android/CameraLauncher.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) mode change 100755 => 100644 src/android/CameraLauncher.java diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java old mode 100755 new mode 100644 index 6d80f73..64d185b --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -380,14 +380,19 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect else if (destType == FILE_URI || destType == NATIVE_URI) { if (this.saveToPhotoAlbum) { Uri inputUri = getUriFromMediaStore(); - //Just because we have a media URI doesn't mean we have a real file, we need to make it - uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); + try { + //Just because we have a media URI doesn't mean we have a real file, we need to make it + uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); + } catch (NullPointerException e) { + uri = null; + } } else { uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); + return; } // If all this is true we shouldn't compress the image. @@ -735,11 +740,11 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException { Uri uri; try { uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException e) { + } catch (RuntimeException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException ex) { + } catch (RuntimeException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); return null; }