I found this issue only in some devices when trying to pick the picture for the profile image. While checking in the emulator these issue are not seen but on live version of the app this issues are facing by this users. Screenshot captured from the firebase crash report. Please help me to figure out the issue.
AndroidMenifest.xml
...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
...
SomeActivity.java
private void pickProfilePictureTask() {
Intent intent = null;
if (Build.VERSION.SDK_INT > 19) {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.addCategory(Intent.CATEGORY_OPENABLE);
} else {
intent = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
intent.setType("image/*");
startActivityForResult(intent, IMAGE_PICKER_REQUEST);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == IMAGE_PICKER_REQUEST && resultCode == Activity.RESULT_OK) {
if (data != null) {
/**Getting bitmap
*
* InputStream inputStream = getActivity().getContentResolver().openInputStream(data.getData());
* Bitmap userPicBitmap = BitmapFactory.decodeStream(inputStream);
*/
File file = new File(getFileNameFromURI(data.getData()));
String imageName = file.getPath();
uploadProfilePicture.setText(imageName);
userProfilePicUri = data.getData() + "";
}
}
}
private String getFileNameFromURI(Uri contentURI) {
String result;
Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) {
result = contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME);
result = cursor.getString(idx);
cursor.close();
}
return result;
}
ERROR in Android 5.1.1 Exception java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider uri content://com.android.providers.media.documents/document/image%3A6617 from pid=19207, uid=10260 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
ERROR in Android 8.0.0 Exception java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{5c1039e 5061:com.mobotechnology.cvmaker/u0a219} (pid=5061, uid=10219) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs