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

修复Android Q下拍照返回图片选择页面的问题 #765

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.zhihu.matisse.internal.utils;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -83,8 +84,12 @@ public void dispatchCaptureIntent(Context context, int requestCode) {

if (photoFile != null) {
mCurrentPhotoPath = photoFile.getAbsolutePath();
mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(),
mCaptureStrategy.authority, photoFile);
if (mCaptureStrategy.isPublic && Platform.hasAndroidQ()) {
mCurrentPhotoUri = createImageUri();
} else {
mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(),
mCaptureStrategy.authority, photoFile);
}
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri);
captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -135,6 +140,12 @@ private File createImageFile() throws IOException {
return tempFile;
}

private Uri createImageUri() {
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, mCurrentPhotoPath);
return mContext.get().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
}

public Uri getCurrentPhotoUri() {
return mCurrentPhotoUri;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ public static boolean hasICS() {
public static boolean hasKitKat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}

public static boolean hasAndroidQ() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
}
}