Merge branch 'master' of git://github.com/phonegap/phonegap-android

This commit is contained in:
macdonst 2011-07-18 16:11:51 -04:00
commit 9bf3a82964
2 changed files with 36 additions and 16 deletions

View File

@ -95,7 +95,13 @@ public class Capture extends Plugin {
obj.put("duration", 0); obj.put("duration", 0);
obj.put("codecs", ""); 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); obj = getImageData(filePath, obj);
} }
else if (filePath.endsWith("audio/3gpp")) { else if (filePath.endsWith("audio/3gpp")) {

View File

@ -18,8 +18,10 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Environment; import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log; import android.util.Log;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
@ -228,16 +230,28 @@ public class FileUtils extends Plugin {
*/ */
private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException { private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
String decoded = URLDecoder.decode(url, "UTF-8"); String decoded = URLDecoder.decode(url, "UTF-8");
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 // Test to see if this is a valid URL first
@SuppressWarnings("unused") @SuppressWarnings("unused")
URL testUrl = new URL(decoded); URL testUrl = new URL(decoded);
File fp = null;
if (decoded.startsWith("file://")) { if (decoded.startsWith("file://")) {
fp = new File(decoded.substring(7, decoded.length())); fp = new File(decoded.substring(7, decoded.length()));
} else { } else {
fp = new File(decoded); fp = new File(decoded);
} }
}
if (!fp.exists()) { if (!fp.exists()) {
throw new FileNotFoundException(); throw new FileNotFoundException();
} }