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);
}
}