Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-7768

captureImage (onActivityResult) in media-capture Plugin Throws FileNotFoundException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • 3.5.0
    • None
    • Samsung Galaxy S5, Android 4.4.4.

    Description

      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); }

      }

      Attachments

        1. Capture.zip
          6 kB
          David Perry

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dp22193 David Perry
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: