not getting the path correctly if the URI contains a file://

Previous to 2.2 this function was crashing if the URI wasn't different
than a 'content://' but still if it is a 'file://' it fails getting the
correct path.
This happens for example picking a picture from dropbox instead of
local gallery.
This commit is contained in:
Alvaro 2012-11-09 09:28:26 +02:00
parent 81f283e56f
commit 1d26239809

View File

@ -1069,16 +1069,18 @@ public class FileUtils extends CordovaPlugin {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected static String getRealPathFromURI(Uri contentUri, CordovaInterface cordova) { protected static String getRealPathFromURI(Uri contentUri, CordovaInterface cordova) {
String uri = contentUri.toString(); final String scheme = contentUri.getScheme();
if (uri.startsWith("content:")) {
if (scheme.compareTo("content") == 0) {
String[] proj = { _DATA }; String[] proj = { _DATA };
Cursor cursor = cordova.getActivity().managedQuery(contentUri, proj, null, null, null); Cursor cursor = cordova.getActivity().managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(_DATA); int column_index = cursor.getColumnIndexOrThrow(_DATA);
cursor.moveToFirst(); cursor.moveToFirst();
return cursor.getString(column_index); return cursor.getString(column_index);
} else if (scheme.compareTo("file") == 0) {
return contentUri.getPath();
} else { } else {
return uri; return contentUri.toString();
} }
} }
} }