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

Workaround solution for Android 30 #819

Open
Arise opened this issue Feb 11, 2021 · 4 comments
Open

Workaround solution for Android 30 #819

Arise opened this issue Feb 11, 2021 · 4 comments

Comments

@Arise
Copy link

Arise commented Feb 11, 2021

Starting with Android 30 external apps no longer can access directly files, so the solution would be to use a custom file provider.

You will have to do those changes:

In CropImage class, add a string customFileProvider :

public static String customFileProvider= "com.theartofdev.edmodo.cropper.genericFileProvider"; // the value is meaningless here, because you will need to override this anyway

Next change getCaptureImageOutputUri function as:

  public static Uri getCaptureImageOutputUri(@NonNull Context context) {
    Uri outputFileUri = null;
    File folder = context.getExternalCacheDir();
    File getImage = new File(folder.getPath(), "pickImageResult.jpeg");
    if (getImage != null) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    	  outputFileUri = FileProvider.getUriForFile(context, customFileProvider,getImage);
      } else{
    	  outputFileUri = Uri.fromFile(getImage);
      }    
    }
    return outputFileUri;
  }

And in getCameraIntent and getCameraIntents you will need to add the permissions as:

intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 

In your app, add the true value for:

CropImage.customFileProvider  = "your.custom.app.package.name"+".genericfileprovider";

Just before making your call to the CropImage library:

CropImage.activity().setOutputUri(outputUri).setCropShape(CropShape.OVAL).setFixAspectRatio(true).start(MyCustomCallingActivity.this);

And at last you need to define the file provider in your AndroidManifest.xml (not going to explain this as is a bit out of the scope).

@Canato
Copy link

Canato commented Feb 17, 2021

THIS LIBRARY IS NOT MAINTAINED, PLEASE READ THIS #818

I start a new project to handover this library
https://github.com/CanHub/Android-Image-Cropper

The ideia is that we keep improving because this project don’t have updates since 2018
Hope I can count with your help.

Open to contribute, next pieces of work will be Android 11 permissions, refactor into Kotlin and ActivityContract

OBS: This issue was solved on the new library =)

@Abhishek95872
Copy link

@Arise Nice man.. It actually worked.. I was wondering what setOutputUri() is.. Then figured out Uri outputUri = Uri.fromFile(new File(requireActivity().getExternalCacheDir(),"image.jpg"));, if anyone required.. Thanks folk..

@ashcode1997
Copy link

@Abhishek95872 how you edited the library ?

@Canato
Copy link

Canato commented Feb 23, 2021

@Abhishek95872 how you edited the library ?

@ashcode1997
We have a new project handover from this one, where we are fixing it all.

https://github.com/CanHub/Android-Image-Cropper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants