1
我有一个代码,执行以下操作:机器人23 URI许可拒绝
- 我得到READ_EXTERNAL_STORAGE和WRITE_EXTERNAL_STORAGE清单中
- 即时得到的照片URI来电话你选择,放入片段插入到viewpager 。
- 它在下面的sdk 22上正常工作。
- 但在Android上进行23它一直在说
权限拒绝java.lang.SecurityException异常:权限拒绝:开放商com.google.android.apps.photos.contentprovioder.MediaContentProvider从ProcessRecord
这是指我的代码线在片段页
/*********************
位图= BitmapFactory.decodeStream(cr.openInputStream (uri),null,option);
其中我把里面的调整大小()方法
**********************/
- 我试图阅读开发控制台文件,并注意我们需要检查权限并询问用户。
我的问题是 1.我应该问其许可,我已经尝试读和写 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);
}
}