From ee06d3efb233d5404d0aeda2abe08e6fd765c7fe Mon Sep 17 00:00:00 2001 From: riknoll Date: Fri, 29 Jan 2016 15:47:00 -0800 Subject: [PATCH] CB-10270 android: Added back support for file:// URIs to getRealPath --- src/android/CameraLauncher.java | 10 ++++++++-- src/android/FileHelper.java | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 15e908fbe..98a95a389 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -688,11 +688,17 @@ else if (destType == FILE_URI || destType == NATIVE_URI) { } catch (Exception e) { e.printStackTrace(); - this.failPicture("Error retrieving image."); + this.failPicture("Error modifying image"); } } else { - this.callbackContext.success(fileLocation); + if (fileLocation != null) { + this.callbackContext.success("file://" + fileLocation); + } else if (uriString != null) { + this.callbackContext.success(uriString); + } else { + this.failPicture("Error retrieving image"); + } } } if (bitmap != null) { diff --git a/src/android/FileHelper.java b/src/android/FileHelper.java index 59f890e19..18093a1b1 100644 --- a/src/android/FileHelper.java +++ b/src/android/FileHelper.java @@ -50,7 +50,17 @@ public class FileHelper { public static String getRealPath(Uri uri, CordovaInterface cordova) { String realPath = null; - if (Build.VERSION.SDK_INT < 11) + if (uri.getScheme().equals("file")) { + String path = uri.getPath(); + if (!path.startsWith("/android_asset/")) { + return path; + } else { + LOG.d(LOG_TAG, "Cannot get real path of an android_asset URI"); + return null; + } + } + + else if (Build.VERSION.SDK_INT < 11) realPath = FileHelper.getRealPathFromURI_BelowAPI11(cordova.getActivity(), uri); // SDK >= 11 && SDK < 19 @@ -209,7 +219,7 @@ public static String getMimeTypeForExtension(String path) { } return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } - + /** * Returns the mime type of the data specified by the given URI string. *