I'm using file helper class from this post https://stackoverflow.com/a/20559175/2281821 but it doesn't working properly in each case. I'm using Intent chooseIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
to start file picker. I have Android Nougat and I'm receiving from onActivityResult uri: content://com.android.externalstorage.documents/document/home%3Aimage.png
What does this home:
means? How can I get access to this file? I was trying with Environment.getExternalStorageDirectory()
and System.getenv("EXTERNAL_STORAGE")
but I can't get acess.
Asked
Active
Viewed 362 times
1
-
2Are u getting any error or exception than plz paste it here also – Ravindra Kushwaha Apr 03 '17 at 06:07
-
There is no error, the path is just incorrect and when I try to create bitmap, it is null – falsetto Apr 03 '17 at 06:56
2 Answers
0
Following code can be used to get document path:
Intent galleryIntent = new Intent();
galleryIntent .setType("image/*");
galleryIntent .setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryIntent , getString(R.string.app_name)),REQUEST_CODE);
OnActivityResult():
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CODE) {
Uri uri = data.getData();
}
}
}
You can use "uri" variable value to get bitmap. If you want to open document other image also then remove following line:
galleryIntent .setType("image/*");

Sonam
- 572
- 4
- 13
0
You get access to a content scheme by opening for instance an InputStream on the uri.
InputStream is = getContentResolver().openInputStream(uri);
BitmapFactory.decodeFromStream(is) will happily read from your stream.

greenapps
- 11,154
- 2
- 16
- 19