Pregunta

From an ACTION_GET_CONTENT intent I can read the filepath of the selected file via a cursor like this:

String[] projection = { MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(data.getData(), projection, null, null, null);
column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
cursor.moveToFirst(); 
capturedImageFilePath = cursor.getString(column_index_data);
cursor.close(); 

which gives me a usable result like this:

/storage/emulated/0/DCIM/Camera/1397538721449.jpg

This works fine on all my test devices, even on Android KitKat devices, except for files from the "Recent" section. capturedImageFilePath is null in this case, and if I try to read the path like this:

Uri myUri = data.getData();
capturedImageFilePath = myUri.getPath();

I get something like this as a result which I can't use to decode the file:

/document/image:237

How do I get the actual file path? It must be possible because other apps on the devices manage to display the correct file but I haven't found any other way to do it on google. Is there a way to get form the file number above to the actual file path?

I have this problem on a Nexus 7 and a Nexus 10 tablet, both running Android 4.4.2.

¿Fue útil?

Solución

Ok, this did the trick:

Uri selectedImageURI = data.getData();
InputStream input = getContentResolver().openInputStream(selectedImageURI);
bmp = BitmapFactory.decodeStream(input);

As I just needed to get the bitmap.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top