It appears that the issue is that the uri returned by the insert method is not properly resolved by openOutputStream. What worked for me was instead of calling openOutputStream, do the following:
String dfname = getRealPathFromURI(uri);
File df = new File(dfname);
File dfolder = df.getParentFile();
if(!dfolder.exists()) dfolder.mkdirs();
if(!df.exists()) df.createNewFile();
FileOutputStream os = new FileOutputStream(df);
private String getRealPathFromURI(Uri contentURI) {
Cursor cursor = this.cordova.getActivity().getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file path
return contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
}
You'll need to import java.io.FileOutputStream, if not already done. I thank Isaac Zais for his answer that pointed me in the right direction and for the getRealPathFromURI code.
It would be great if a Cordova developer could explain if this is a bug in org.apache.cordova.media-capture or somewhere else or if there is a way to get this to work without having to modify the latest version of the plugin.
Tested on Samsung Galaxy S5, Android 4.4.4.