cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Perry (JIRA)" <>
Subject [jira] [Commented] (CB-7768) captureImage (onActivityResult) in media-capture Plugin Throws FileNotFoundException
Date Wed, 14 Oct 2015 18:10:05 GMT


David Perry commented on CB-7768:

[~bowserj], Is this a bug or not?  I have reported a bug with a suggested solution. I am not
a Cordova developer. I do not have an in-depth knowledge of how all the pieces work together
and I am very uncomfortable updating the code without someone more intimate with the code
saying this fix is a viable solution that won't break something now or in the future.  If
it is a bug, it should be fixed rather than closed, regardless of a pull request.  If my solution
is a viable solution, I am perfectly fine with a Cordova developer fixing it and taking credit
for it.  If my solution is not the best way to fix it, that's fine too.  Fix it however you
(the Cordova developers) see fit.

> captureImage (onActivityResult) in media-capture Plugin Throws FileNotFoundException
> ------------------------------------------------------------------------------------
>                 Key: CB-7768
>                 URL:
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 3.5.0
>         Environment: Samsung Galaxy S5, Android 4.4.4.
>            Reporter: David Perry
>         Attachments:
> It appears that the issue is that the uri returned by that.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values) is not properly resolved by OutputStream os = that.cordova.getActivity().getContentResolver().openOutputStream(uri).
> 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); 
>     }
> }

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message