Skip to content

Android11 打开相册选择图片返回后无法显示。 #883

@fddlpz

Description

@fddlpz

Android11 打开相册选择图片返回后无法显示。拍照没有问题
报错:
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider uri content://com.android.providers.media.documents/document/image%3A35 from pid=25351, uid=10155 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs

现使用代码:

private Intent getFileChooserIntent() {
	Intent mIntent = null;
	if (mIsAboveLollipop && mFileChooserParams != null && (mIntent = mFileChooserParams.createIntent()) != null) {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && mIntent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
			mIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
		}
		return mIntent;
	}

	Intent i = new Intent();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		i.setAction(Intent.ACTION_OPEN_DOCUMENT);
	} else {
		i.setAction(Intent.ACTION_GET_CONTENT);
	}
	i.addCategory(Intent.CATEGORY_OPENABLE);
	if (TextUtils.isEmpty(this.mAcceptType)) {
		i.setType("*/*");
	} else {
		i.setType(this.mAcceptType);
	}
	i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
	return mIntent = Intent.createChooser(i, "");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions