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

Fixed scoped storage issue on Android 10 #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 15 additions & 3 deletions cropper/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<manifest
package="com.theartofdev.edmodo.cropper">
<manifest package="com.theartofdev.edmodo.cropper"
xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
<application>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>

</manifest>
49 changes: 11 additions & 38 deletions cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,7 @@ public static Intent getPickImageChooserIntent(
allIntents.addAll(getCameraIntents(context, packageManager));
}

List<Intent> 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()) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -262,35 +256,14 @@ public static List<Intent> getCameraIntents(
* Get all Gallery intents for getting image from one of the apps of the device that handle
* images.
*/
public static List<Intent> getGalleryIntents(
@NonNull PackageManager packageManager, String action, boolean includeDocuments) {
List<Intent> 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<ResolveInfo> 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;
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions cropper/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path
name="cache_files"
path="."/>
</paths>