From e789349c23993d8ac020155fc7ab276716cb6e7c Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 19 Jul 2011 03:57:02 +0800 Subject: [PATCH 1/2] Handle content:// uri's in resolveLocalFileSystemURI Sometimes Android will hand you a content:// uri in the place of a file path. Particularily the Camera.getPicture() code will do this. I've updated the file utils code to handle this type of uri and return a real file path. --- framework/src/com/phonegap/Capture.java | 8 ++++- framework/src/com/phonegap/FileUtils.java | 44 +++++++++++++++-------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/framework/src/com/phonegap/Capture.java b/framework/src/com/phonegap/Capture.java index 25ed6460..b078e5df 100644 --- a/framework/src/com/phonegap/Capture.java +++ b/framework/src/com/phonegap/Capture.java @@ -95,7 +95,13 @@ public class Capture extends Plugin { obj.put("duration", 0); obj.put("codecs", ""); - if (mimeType.equals("image/jpeg")) { + // If the mimeType isn't set the rest will fail + // so let's see if we can determine it. + if (mimeType == null || mimeType.equals("")) { + mimeType = FileUtils.getMimeType(filePath); + } + + if (mimeType.equals("image/jpeg") || filePath.endsWith(".jpg")) { obj = getImageData(filePath, obj); } else if (filePath.endsWith("audio/3gpp")) { diff --git a/framework/src/com/phonegap/FileUtils.java b/framework/src/com/phonegap/FileUtils.java index c707f293..240a507e 100755 --- a/framework/src/com/phonegap/FileUtils.java +++ b/framework/src/com/phonegap/FileUtils.java @@ -18,8 +18,10 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import android.database.Cursor; import android.net.Uri; import android.os.Environment; +import android.provider.MediaStore; import android.util.Log; import android.webkit.MimeTypeMap; @@ -228,22 +230,34 @@ public class FileUtils extends Plugin { */ private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException { String decoded = URLDecoder.decode(url, "UTF-8"); - // Test to see if this is a valid URL first - @SuppressWarnings("unused") - URL testUrl = new URL(decoded); + + File fp = null; + + // Handle the special case where you get an Android content:// uri. + if (decoded.startsWith("content:")) { + Cursor cursor = this.ctx.managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null); + // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data" + int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + fp = new File(cursor.getString(column_index)); + } else { + // Test to see if this is a valid URL first + @SuppressWarnings("unused") + URL testUrl = new URL(decoded); + + if (decoded.startsWith("file://")) { + fp = new File(decoded.substring(7, decoded.length())); + } else { + fp = new File(decoded); + } + } - File fp = null; - if (decoded.startsWith("file://")) { - fp = new File(decoded.substring(7, decoded.length())); - } else { - fp = new File(decoded); - } - if (!fp.exists()) { - throw new FileNotFoundException(); - } - if (!fp.canRead()) { - throw new IOException(); - } + if (!fp.exists()) { + throw new FileNotFoundException(); + } + if (!fp.canRead()) { + throw new IOException(); + } return getEntry(fp); } From 7afa2d38409cd3c5a850683703f61f09d4b875e6 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 19 Jul 2011 00:48:26 +0800 Subject: [PATCH 2/2] Upping version to 1.0.0rc2 --- VERSION | 2 +- example/index.html | 2 +- framework/assets/www/index.html | 2 +- framework/src/com/phonegap/Device.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 6a056a8b..8862dbae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0rc1 +1.0.0rc2 diff --git a/example/index.html b/example/index.html index 494e678e..10a69d06 100644 --- a/example/index.html +++ b/example/index.html @@ -5,7 +5,7 @@ PhoneGap - + diff --git a/framework/assets/www/index.html b/framework/assets/www/index.html index f2c27e37..e742b835 100644 --- a/framework/assets/www/index.html +++ b/framework/assets/www/index.html @@ -1,7 +1,7 @@ - + diff --git a/framework/src/com/phonegap/Device.java b/framework/src/com/phonegap/Device.java index 03755739..60858bc9 100644 --- a/framework/src/com/phonegap/Device.java +++ b/framework/src/com/phonegap/Device.java @@ -18,7 +18,7 @@ import android.provider.Settings; public class Device extends Plugin { - public static String phonegapVersion = "1.0.0rc1"; // PhoneGap version + public static String phonegapVersion = "1.0.0rc2"; // PhoneGap version public static String platform = "Android"; // Device OS public static String uuid; // Device UUID