我有一个执行以下操作的代码:
权限否认java.lang.SecurityException:Permission Denial:从ProcessRecord打开提供程序com.google.android.apps.photos.contentprovioder.MediaContentProvider
这是指我在片段页面中的代码
/ *********************
bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri),null,option);
我把它放在reSize()方法里面
********************** /
我的问题是 1.我应该问哪个权限,我试过READ和WRITE 2.我应该在哪里包围检查权限,它是在方法之外?或者只围绕这条线。
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int hasPermission = checkSelfPermission(context,
Manifest.permission.READ_EXTERNAL_STORAGE);
if (hasPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
RESULT_PERMS_INITIAL);
} else {
bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri), null, option);
}
} else {
bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri), null, option);
}
并根据结果要求
public void onRequestPermissionsResult(int requestCode,
String[] permissions,
int[] grantResults) {
if (requestCode == RESULT_PERMS_INITIAL) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
bitmap = resizeBitmap(uri, getActivity().getApplicationContext());
}
else {
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show();
}
}
else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}