When picking an image using an ACTION_GET_CONTENT
intent, I get a URI that I can't open the file from. If I try to open the file, like this:
InputStream in = new FileInputStream(new File(uri.getPath()));
It gives the following exception:
03-11 15:14:36.132 20557-20557/my.package W/System.err﹕ java.io.FileNotFoundException: /document/image:9537: open failed: ENOENT (No such file or directory)
03-11 15:14:36.138 20557-20557/my.package W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:456)
03-11 15:14:36.138 20557-20557/my.package W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:76)
/document/image:9537
seems to indeed be an incorrect path, but how do I get the correct path?
I use this logic to open the image picker:
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
photoPickerIntent.putExtra("return-data", false);
startActivityForResult(Intent.createChooser(photoPickerIntent, "Complete action using"), PICK_FROM_FILE);
And retrieve the Uri in the onActivityResult like this:
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
....
Uri uri = data.getData();
I need to get the file to do decoding to make it smaller.