权限被拒绝从Android画廊中读取

时间:2018-08-04 12:38:44

标签: android android-gallery

我正在使用Android应用程序,该应用程序从画廊获取图像并显示它...但是它显示空白屏幕,错误是:

Unable to decode stream: java.io.FileNotFoundException: /storage...jpeg: open failed: EACCES (Permission denied)

代码:

image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            image.setImageBitmap(BitmapFactory.decodeFile(picturePath));
    }
}

并且我已经添加了AndroidManifest:

android:name="android.permission.READ_EXTERNAL_STORAGE"

0 个答案:

没有答案