From 57570d7b877f0e3766bf86921ca9b7c1ff25de1f Mon Sep 17 00:00:00 2001 From: teach Date: Thu, 12 Sep 2019 17:21:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89Fi?= =?UTF-8?q?leProvider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 11 ----------- app/src/main/res/xml/file_paths.xml | 8 -------- imageselector/src/main/AndroidManifest.xml | 14 ++++++++++---- .../imageselector/ImageSelectorActivity.java | 13 ++++++++++--- .../provider/ImageSelectorProvider.java | 13 +++++++++++++ .../imageselector/utils/VersionUtils.java | 3 +-- .../src/main/res/xml/image_selector_file_paths.xml | 9 +++++++++ 7 files changed, 43 insertions(+), 28 deletions(-) delete mode 100644 app/src/main/res/xml/file_paths.xml create mode 100644 imageselector/src/main/java/com/donkingliang/imageselector/provider/ImageSelectorProvider.java create mode 100644 imageselector/src/main/res/xml/image_selector_file_paths.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 08f2232..3baa671 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,17 +32,6 @@ android:configChanges="orientation|keyboardHidden|screenSize" android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> - - - - - \ No newline at end of file diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml deleted file mode 100644 index 054c006..0000000 --- a/app/src/main/res/xml/file_paths.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/imageselector/src/main/AndroidManifest.xml b/imageselector/src/main/AndroidManifest.xml index da6cf18..b6be707 100644 --- a/imageselector/src/main/AndroidManifest.xml +++ b/imageselector/src/main/AndroidManifest.xml @@ -2,10 +2,16 @@ package="com.donkingliang.imageselector"> - + android:label="@string/app_name"> + + + diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java b/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java index da62208..e41d589 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java @@ -82,6 +82,7 @@ public class ImageSelectorActivity extends AppCompatActivity { private static final int CAMERA_REQUEST_CODE = 0x00000010; private Uri mCameraUri; + private String mCameraImagePath; private boolean isOpenFolder; private boolean isShowTime; @@ -560,9 +561,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } } else if (requestCode == CAMERA_REQUEST_CODE) { if (resultCode == RESULT_OK) { - sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraUri)); ArrayList images = new ArrayList<>(); - images.add(UriUtils.getPathForUri(this, mCameraUri)); + if (VersionUtils.isAndroidQ()) { + sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, mCameraUri)); + images.add(UriUtils.getPathForUri(this, mCameraUri)); + } else { + sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(mCameraImagePath)))); + images.add(mCameraImagePath); + } saveImageAndFinish(images, true); } } @@ -727,9 +733,10 @@ private void openCamera() { } if (photoFile != null) { + mCameraImagePath = photoFile.getAbsolutePath(); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { //通过FileProvider创建一个content类型的Uri - photoUri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", photoFile); + photoUri = FileProvider.getUriForFile(this, getPackageName() + ".imageSelectorProvider", photoFile); } else { photoUri = Uri.fromFile(photoFile); } diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/provider/ImageSelectorProvider.java b/imageselector/src/main/java/com/donkingliang/imageselector/provider/ImageSelectorProvider.java new file mode 100644 index 0000000..3bf3321 --- /dev/null +++ b/imageselector/src/main/java/com/donkingliang/imageselector/provider/ImageSelectorProvider.java @@ -0,0 +1,13 @@ +package com.donkingliang.imageselector.provider; + +import android.support.v4.content.FileProvider; + +/** + * @Author teach liang + * @Description + * @Date 2019/9/12 + */ +public class ImageSelectorProvider extends FileProvider { + + +} diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/utils/VersionUtils.java b/imageselector/src/main/java/com/donkingliang/imageselector/utils/VersionUtils.java index 55a9f99..845d93b 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/utils/VersionUtils.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/utils/VersionUtils.java @@ -15,7 +15,6 @@ public class VersionUtils { * @return */ public static boolean isAndroidQ() { - return true; -// return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; } } diff --git a/imageselector/src/main/res/xml/image_selector_file_paths.xml b/imageselector/src/main/res/xml/image_selector_file_paths.xml new file mode 100644 index 0000000..058bc62 --- /dev/null +++ b/imageselector/src/main/res/xml/image_selector_file_paths.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file