I am trying to make user pick an image from gallery, display it in imageView, and at the same time, create a byte array of the same file.
After debugging:
'new File(filepath)' executed no problem, with a valid filesystem path.
but it always skips 'ByteArrayOutputStream baos = new ByteArrayOutputStream();' to the IOException with a java.ioFileNotFoundException
any idea what im doing wrong?
or is there a more efficient way i can just convert a byte of a file to a HEX character, and send each HEX char until the last byte of the file?
try {
File myFile = new File(imageUri.getPath());
String filepath = myFile.getAbsolutePath();
Log.d("onActivityResult", "filepath: " + filepath);
FileOutputStream fos = new FileOutputStream ( new File(filepath) );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Put data in your baos
baos.writeTo(fos);
} catch(IOException ioe) {
// Handle exception here
ioe.printStackTrace();
Toast.makeText(this, "Byte buffer error.", Toast.LENGTH_LONG).show();
}
GET_CONTENTor equivalent methods of picking an image does not return aFilewith a path on recent versions of Android.FileNotFoundExceptionvery clearly points to the fact that no, you do not have a valid File.GET_CONTENT.