0
 private void handleImageData(Uri data) {
    if(data != null){
        file = new File(data.getPath());
        capturedImageView.setImageURI(data);
    }
    else {
        AndyUtils.showErrorToast("Invalid Uri", this );
    }
}

I am always getting file as null. i know this is not right way. what am i missing?

pecific_rim
  • 105
  • 1
  • 10

1 Answers1

1

You should get the InputStream from the Uri and then save it to a file. Something like this (code might need some improvement):

File file = new File("path");

//get InputStream
ContentResolver cr = context.getContentResolver();
InputStream is = cr.openInputStream( fileUri );

//write to file
FileOutputStream fos = new FileOutputStream( file );
byte[] buffer = new byte[ 1024 ];
int count;
while ( ( count = is.read( buffer ) ) != -1 ) {
    fos.write( buffer, 0, count );
    fos.flush();
}

//close everything
fos.close();
is.close();
Eduardo Herzer
  • 2,033
  • 21
  • 24