From 12cee4c35ce5a9b5d24ad720ed51144f35f572d3 Mon Sep 17 00:00:00 2001 From: Joky Date: Mon, 20 Apr 2020 09:33:06 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8DAndroid=20Q=E4=B8=8B?= =?UTF-8?q?=E6=8B=8D=E7=85=A7=E8=BF=94=E5=9B=9E=E5=9B=BE=E7=89=87=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../matisse/internal/utils/MediaStoreCompat.java | 15 +++++++++++++-- .../zhihu/matisse/internal/utils/Platform.java | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java index 592c77ea6..4253ac110 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java @@ -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; @@ -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) { @@ -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; } diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java b/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java index df41989ae..13f5367e8 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java @@ -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; + } } From 0e426296d907e5f45375e5617f19d5ddc67a966b Mon Sep 17 00:00:00 2001 From: Joky Date: Mon, 20 Apr 2020 09:54:13 +0800 Subject: [PATCH 2/6] code style --- .../java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java | 2 +- .../main/java/com/zhihu/matisse/internal/utils/Platform.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java index 4253ac110..6a2480a46 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java @@ -84,7 +84,7 @@ public void dispatchCaptureIntent(Context context, int requestCode) { if (photoFile != null) { mCurrentPhotoPath = photoFile.getAbsolutePath(); - if (mCaptureStrategy.isPublic && Platform.hasAndroidQ()){ + if (mCaptureStrategy.isPublic && Platform.hasAndroidQ()) { mCurrentPhotoUri = createImageUri(); } else { mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(), diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java b/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java index 13f5367e8..89c026f94 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/utils/Platform.java @@ -14,7 +14,7 @@ public static boolean hasKitKat() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; } - public static boolean hasAndroidQ(){ + public static boolean hasAndroidQ() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; } } From a4def4d48100abd71676ec157530429c75b64662 Mon Sep 17 00:00:00 2001 From: Joky Date: Mon, 20 Apr 2020 10:17:52 +0800 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6894a2178..1b317d010 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![Image](/image/banner.png) # Matisse -[![Build Status](https://travis-ci.org/zhihu/Matisse.svg)](https://travis-ci.org/zhihu/Matisse) [ ![Download](https://api.bintray.com/packages/zhihu/maven/matisse/images/download.svg) ](https://bintray.com/zhihu/maven/matisse/_latestVersion) +[![Build Status](https://travis-ci.org/Joky-SSS/Matisse.svg)](https://travis-ci.org/Joky-SSS/Matisse) [ ![Download](https://api.bintray.com/packages/zhihu/maven/matisse/images/download.svg) ](https://bintray.com/zhihu/maven/matisse/_latestVersion) Matisse is a well-designed local image and video selector for Android. You can - Use it in Activity or Fragment From b87127ebd79d53efeb036ada6da044a7c9a31da0 Mon Sep 17 00:00:00 2001 From: Joky Date: Mon, 20 Apr 2020 10:22:00 +0800 Subject: [PATCH 4/6] Revert "Update README.md" This reverts commit a4def4d4 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b317d010..6894a2178 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![Image](/image/banner.png) # Matisse -[![Build Status](https://travis-ci.org/Joky-SSS/Matisse.svg)](https://travis-ci.org/Joky-SSS/Matisse) [ ![Download](https://api.bintray.com/packages/zhihu/maven/matisse/images/download.svg) ](https://bintray.com/zhihu/maven/matisse/_latestVersion) +[![Build Status](https://travis-ci.org/zhihu/Matisse.svg)](https://travis-ci.org/zhihu/Matisse) [ ![Download](https://api.bintray.com/packages/zhihu/maven/matisse/images/download.svg) ](https://bintray.com/zhihu/maven/matisse/_latestVersion) Matisse is a well-designed local image and video selector for Android. You can - Use it in Activity or Fragment From 602a739759279a8d3e8d9d54101bf5a6fc7355db Mon Sep 17 00:00:00 2001 From: Joky Date: Tue, 21 Apr 2020 14:53:33 +0800 Subject: [PATCH 5/6] fix bug --- .../internal/utils/MediaStoreCompat.java | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java index 6a2480a46..dfe4dd55e 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java @@ -75,21 +75,25 @@ public void setCaptureStrategy(CaptureStrategy strategy) { public void dispatchCaptureIntent(Context context, int requestCode) { Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (captureIntent.resolveActivity(context.getPackageManager()) != null) { - File photoFile = null; - try { - photoFile = createImageFile(); - } catch (IOException e) { - e.printStackTrace(); - } + if (mCaptureStrategy.isPublic && Platform.hasAndroidQ()) { + mCurrentPhotoUri = createImageUri(); + if (mCurrentPhotoUri != null) + mCurrentPhotoPath = PathUtils.getPath(mContext.get(), mCurrentPhotoUri); + } else { + File photoFile = null; + try { + photoFile = createImageFile(); + } catch (IOException e) { + e.printStackTrace(); + } - if (photoFile != null) { - mCurrentPhotoPath = photoFile.getAbsolutePath(); - if (mCaptureStrategy.isPublic && Platform.hasAndroidQ()) { - mCurrentPhotoUri = createImageUri(); - } else { + if (photoFile != null) { + mCurrentPhotoPath = photoFile.getAbsolutePath(); mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(), mCaptureStrategy.authority, photoFile); } + } + if (mCurrentPhotoUri != null) { captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri); captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { @@ -140,9 +144,18 @@ private File createImageFile() throws IOException { return tempFile; } + @TargetApi(Build.VERSION_CODES.Q) private Uri createImageUri() { + String relativePath = Environment.DIRECTORY_PICTURES; + if (mCaptureStrategy.directory != null) { + relativePath += File.separator + mCaptureStrategy.directory; + } + String timeStamp = + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); + String imageFileName = String.format("JPEG_%s.jpg", timeStamp); ContentValues values = new ContentValues(); - values.put(MediaStore.MediaColumns.DATA, mCurrentPhotoPath); + values.put(MediaStore.Images.Media.DISPLAY_NAME, imageFileName); + values.put(MediaStore.MediaColumns.RELATIVE_PATH, relativePath); return mContext.get().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } From 7ef3cdff4e27d9afd082844239a701b16c0455c6 Mon Sep 17 00:00:00 2001 From: Joky Date: Tue, 21 Apr 2020 15:02:20 +0800 Subject: [PATCH 6/6] miss import --- .../java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java | 1 + 1 file changed, 1 insertion(+) diff --git a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java index dfe4dd55e..c629c6655 100644 --- a/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java +++ b/matisse/src/main/java/com/zhihu/matisse/internal/utils/MediaStoreCompat.java @@ -15,6 +15,7 @@ */ package com.zhihu.matisse.internal.utils; +import android.annotation.TargetApi; import android.app.Activity; import android.content.ContentValues; import android.content.Context;