From 0d92bbf6ba06c537d4c7361f1ed51623ed7c7804 Mon Sep 17 00:00:00 2001 From: Ravindu W Date: Mon, 20 Jan 2020 22:37:54 +1100 Subject: [PATCH] Fixed scoped storage issue on Android 10 --- build.gradle | 4 +- cropper/src/main/AndroidManifest.xml | 18 +++++-- .../theartofdev/edmodo/cropper/CropImage.java | 49 +++++-------------- cropper/src/main/res/xml/provider_paths.xml | 6 +++ 4 files changed, 34 insertions(+), 43 deletions(-) create mode 100644 cropper/src/main/res/xml/provider_paths.xml diff --git a/build.gradle b/build.gradle index 24d6cbf9..d68d3c95 100644 --- a/build.gradle +++ b/build.gradle @@ -18,8 +18,8 @@ allprojects { } ext { - compileSdkVersion = 28 - buildToolsVersion = '28.0.3' + compileSdkVersion = 29 + buildToolsVersion = '29.0.2' androidXLibraryVersion = '1.0.0' PUBLISH_GROUP_ID = 'com.theartofdev.edmodo' diff --git a/cropper/src/main/AndroidManifest.xml b/cropper/src/main/AndroidManifest.xml index 674ba03a..f11e0c80 100644 --- a/cropper/src/main/AndroidManifest.xml +++ b/cropper/src/main/AndroidManifest.xml @@ -1,4 +1,16 @@ - + - + + + + + + + \ No newline at end of file diff --git a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImage.java b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImage.java index ba8b807b..4d408978 100644 --- a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImage.java +++ b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImage.java @@ -189,13 +189,7 @@ public static Intent getPickImageChooserIntent( allIntents.addAll(getCameraIntents(context, packageManager)); } - List galleryIntents = - getGalleryIntents(packageManager, Intent.ACTION_GET_CONTENT, includeDocuments); - if (galleryIntents.size() == 0) { - // if no intents found for get-content try pick intent action (Huawei P9). - galleryIntents = getGalleryIntents(packageManager, Intent.ACTION_PICK, includeDocuments); - } - allIntents.addAll(galleryIntents); + allIntents.add(getGalleryIntent(Intent.ACTION_GET_CONTENT, includeDocuments)); Intent target; if (allIntents.isEmpty()) { @@ -210,7 +204,7 @@ public static Intent getPickImageChooserIntent( // Add all other intents chooserIntent.putExtra( - Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()])); + Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()])); return chooserIntent; } @@ -262,35 +256,14 @@ public static List getCameraIntents( * Get all Gallery intents for getting image from one of the apps of the device that handle * images. */ - public static List getGalleryIntents( - @NonNull PackageManager packageManager, String action, boolean includeDocuments) { - List intents = new ArrayList<>(); - Intent galleryIntent = - action == Intent.ACTION_GET_CONTENT - ? new Intent(action) - : new Intent(action, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); - galleryIntent.setType("image/*"); - List listGallery = packageManager.queryIntentActivities(galleryIntent, 0); - for (ResolveInfo res : listGallery) { - Intent intent = new Intent(galleryIntent); - intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); - intent.setPackage(res.activityInfo.packageName); - intents.add(intent); - } - - // remove documents intent - if (!includeDocuments) { - for (Intent intent : intents) { - if (intent - .getComponent() - .getClassName() - .equals("com.android.documentsui.DocumentsActivity")) { - intents.remove(intent); - break; - } - } - } - return intents; + public static Intent getGalleryIntent(String action, boolean includeDocuments) { + + Intent galleryIntent = new Intent(); + galleryIntent.setAction(action); + galleryIntent.setType(includeDocuments ? "*/*" : "image/*"); + galleryIntent.addCategory(Intent.CATEGORY_OPENABLE); + + return galleryIntent; } /** @@ -522,7 +495,7 @@ public void start(@NonNull Context context, @NonNull android.app.Fragment fragme * @param fragment fragment to receive result */ public void start( - @NonNull Context context, @NonNull Fragment fragment, @Nullable Class cls) { + @NonNull Context context, @NonNull Fragment fragment, @Nullable Class cls) { fragment.startActivityForResult(getIntent(context, cls), CROP_IMAGE_ACTIVITY_REQUEST_CODE); } diff --git a/cropper/src/main/res/xml/provider_paths.xml b/cropper/src/main/res/xml/provider_paths.xml new file mode 100644 index 00000000..dca90ab1 --- /dev/null +++ b/cropper/src/main/res/xml/provider_paths.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file