Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
fddlpz opened this issue Nov 23, 2020 · 8 comments
Closed

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

fddlpz opened this issue Nov 23, 2020 · 8 comments

Comments

@fddlpz
Copy link

fddlpz commented Nov 23, 2020

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, "");
}
@mengsr
Copy link

mengsr commented Jan 12, 2021

解决了么?

@mengsr
Copy link

mengsr commented Jan 13, 2021

rivate Uri[] processData(Intent data) {
Uri[] datas = null;
if (data == null) {
return datas;
}
String target = data.getDataString();
if (!TextUtils.isEmpty(target)) {
String[] path = AgentWebUtils.uriToPath(mActivity, new Uri[]{Uri.parse(target)});
datas = new Uri[path.length];
File file;
for (int i = 0; i < path.length; i++) {
file = new File(path[i]);
datas[i] = Uri.fromFile(file);
}
return datas;
}
ClipData mClipData = data.getClipData();
if (mClipData != null && mClipData.getItemCount() > 0) {
datas = new Uri[mClipData.getItemCount()];
for (int i = 0; i < mClipData.getItemCount(); i++) {

        ClipData.Item mItem = mClipData.getItemAt(i);
        datas[i] = mItem.getUri();

    }
}
return datas;

}

@VectorWen
Copy link

解决了吗

@mengsr
Copy link

mengsr commented Mar 3, 2021 via email

@Aaroneee
Copy link

Aaroneee commented Apr 9, 2021

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

老哥,这个问题解决了吗?怎么解决的

@yzcheng90
Copy link

老哥,完整代码可以贴一下吗

Justson added a commit that referenced this issue Nov 24, 2021
@XuRan-Zhao-lucky
Copy link

解决了吗

@Aaroneee
Copy link

解决了吗

更新版本后就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants