Skip to content
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;
}
}