I want to get bitmap by uri by:
MediaStore.Images.Media.getBitmap(context.getContentResolver(), Uri.parse(uri))
but this code throw a exception says:
java.lang.SecurityException: Permission Denial: opening provider
com.android.providers.media.MediaDocumentsProvider from
ProcessRecord{430b1748 29271:com.x.x.x/u0a88} (pid=29271, uid=10088)
requires android.permission.MANAGE_DOCUMENTS or
android.permission.MANAGE_DOCUMENTS
and My build gradle:
compileSdkVersion 26
minSdkVersion 23
targetSdkVersion 23
I know that I need to ask for permission dynamically.
I have this In my fragment:
int hasWriteContactsPermission = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.MANAGE_DOCUMENTS);
if (hasWriteContactsPermission == PackageManager.PERMISSION_GRANTED) {
generateGridView();
}
else {
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_PHONE_STATE}, MANAGE_DOCUMENTS_REQUEST_CODE);
}
I debug this code, And I found that requestPermissions can not trigger the dialog to show for asking permission. And -1 was returned as grantResults in onRequestPermissionsResult.
In my only manifest I have:
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
actually, I know there's a same question there, But I have no reputation to comment and ask more there!! I have the same code as the accepted answer, but does not solve the problem. This really driven me crazy. SO is really unfriendly to normal coder that only sometime want to ask!