ArthurHub/Android-Image-Cropper

I'm facing issue in Android 11 what to do?

Raj-spbi opened this issue ยท 32 comments

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaratechnologies.sharegrapesapp/com.theartofdev.edmodo.cropper.CropImageActivity}: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.aaratechnologies.sharegrapesapp/cache/pickImageResult.jpeg exposed beyond app through ClipData.Item.getUri()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3704)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3871)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2301)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:260)
at android.app.ActivityThread.main(ActivityThread.java:8245)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)

startActivityForResult is not working in api level 11 so you have to update your code from documentation.

๐Ÿšจ๐Ÿšจ๐Ÿšจ๐Ÿšจ๐Ÿšจ THIS LIBRARY IS NOT MAINTAINED, PLEASE READ THIS ๐Ÿšจ๐Ÿšจ๐Ÿšจ๐Ÿšจ๐Ÿšจ #838

To avoid your issues, please use the latest updated library: https://github.com/CanHub/Android-Image-Cropper

100% kotlin
All bugs fixes
active community
25k downloads per month

Add in manifest and it will work but not for camera. am also looking for camera as it's getting crashed.

<queries> <!-- Camera --> <intent> <action android:name="android.media.action.IMAGE_CAPTURE" /> </intent> <!-- Gallery --> <intent> <action android:name="android.intent.action.GET_CONTENT" /> <data android:mimeType="image/*" /> </intent> </queries>

@sitaram-gupta the right is update to the new project, so everything will work.

A guide how to update

@Canato Thank you but all is working except Camera.

Did you checked the case with old OSs for Huawei phones and Samsung ones that change the default Android path for the content:// schema folder?

This was one of the biggest issues cause just some specific combinations of device and OSs make it fail.

Plus the Android 11 bug is related to the permission that don't exist anymore, was deprecated on Android 10, but file external storage was removed from Android 11.
And this library, in this version, still rely on it for cropping.

@Canato Thanks again for the such a great information. And can i use this library for android java because my older projects are in Java so?

@sitaram-gupta yes, we even have a sample in Java. But if find any bugs please raise a issue or PR ^^

@Canato Sure, Thanks!

@Canato can you keep here sample for the java ? I couldn't get run from above as there is a lot of errors in java while building project.

@Canato can you keep here sample for the java ? I couldn't get run from above as there is a lot of errors in java while building project.

@sitaram-gupta we cannot change anything in this repository. Please look the CanHuB repository and check the sample folder. There is a Java sample there

@Canato can you upload a java example for extended activity in your code for extend_activity package version, Since i am new to kotlin i find it difficult to understand your code.
I already have a fragment through which i have 3 requirements, so something similar would be very helpful

  1. From a fragment on button click->Open only Camera directly->Capture image and give image url or file url back to fragment
  2. From a fragment->pass the previously obtained path url to CropActivity & get back the result image path & file path.
  3. As usual i need extended activity to add bottom bar to perform rotate left, rotate rigt, reset & crop or save and finally discard changes and get updated result to calling fragment.

If these many requests are no possible if you can simply copy paste what changes needs to be done to this project so it can used for Android 11 can be helpful. thanks in advance :)

@r4jjin please use the new repository for questions and issues.

Check the sample folder, there is a Java sample there using the library

@r4jjin please use the new repository for questions and issues.

Check the sample folder, there is a Java sample there using the library

Hello @Canato , as i said earlier. you have couple of change in your code which includes activity contracts, view bindings, mvp pattern, provider as compared to existing project. So to adapt, if you provide a similar example which is mentioned would be more helpful under the sample folder in java, due to time constraint and learning curve. As of now I see SExtendActivity is written in kotlin.

From a fragment on button click->Open only Camera directly->Capture image and give image url or file url back to fragment
From a fragment->pass the previously obtained path url to CropActivity & get back the result image path & file path.
As usual i need extended activity to add bottom bar to perform rotate left, rotate rigt, reset & crop or save and finally discard changes and get updated result to calling fragment.

JAVA
@r4jjin I just migrated from theartofdev to canhub. It could help you can try. Github

JAVA
@r4jjin I just migrated from theartofdev to canhub. It could help you can try. Github

Thanks for the reference @sitaram-gupta . Let me go through the codebase.

JAVA
@r4jjin I just migrated from theartofdev to canhub. It could help you can try. Github

Hello,
I noticed, you are checking for permission and using on ActivityResult, which is deprecated in A11. Could you provide Activity Contract to fetch the result obtained from camera after click as image url or file path.

@r4jjin there is no use of permission i had just kept for other purpose so i removed and pushed fresh code please have a look.

@sitaram-gupta I checked the code. In this i don't want to see the Gallery & File intent, just directly launching Camera without asking for any other options is needed. Also when taking capture from Camera the image is not obtained. I appreciate your help, but could you help me with these as well. If possible using ActivityContract in the same example.

@r4jjin Please check, I have updated.

Android 11 using camera crop not working intent data is null please help asap

Please create issue here! Create Issue

Android 11 using camera crop not working intent data is null please help asap

@hareshmunjapara update your library to https://github.com/CanHub/Android-Image-Cropper

@Canato i am using java code please solve it

AppUtil.doCrop(SurvayDetailActivity.this); // call this method

@SuppressLint("QueryPermissionsNeeded")
public static void doCrop(Activity activity) {
if (activity.getIntent().resolveActivity(activity.getPackageManager()) != null) {
CropImage.activity().setGuidelines(CropImageView.Guidelines.ON)
.setActivityTitle(activity.getResources().getString(R.string.cropImage)) //Crop Image
.setCropShape(CropImageView.CropShape.RECTANGLE)
.setCropMenuCropButtonTitle(activity.getResources().getString(R.string.crop_done)) //Done
.setFixAspectRatio(true)
.setRequestedSize(600, 600)
.start(activity);
}
}

//onActivityResult()

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (data != null && resultCode == Activity.RESULT_OK) {
    CropImage.ActivityResult data1 = CropImage.getActivityResult(data);
    Uri bitmap = data1.getUri();
    Bitmap photo = BitmapFactory.decodeFile(bitmap.getPath(), new BitmapFactory.Options());
    ePhoto = getBytesFromBitmap(photo);

@Canato i am using java code please solve it

@hareshmunjapara update your library to https://github.com/CanHub/Android-Image-Cropper
It work with Java. If don't work, open an issue.

Here is the sample app in Java using the library https://github.com/CanHub/Android-Image-Cropper/tree/main/sample/src/main/java/com/canhub/cropper/sample/crop_image_java

The library is in Kotlin because is better, but is Java friendly and possible to use.

The old library (this repo) have bugs and will not work

CropImage.ActivityResult result = CropImage.getActivityResult(data); String filePath = result.getUriFilePath(ProfileDocumentActivity.this, true); File file= new File(filePath);

thanks for your support @sitaram-gupta :) managed to get it working.. thanks @Canato for the library as well, i hope adding more java oriented example under sample module can be helpful for beginners ๐Ÿ‘

@r4jjin agree, please feel free to drop some PR with samples =D

@Canato sure, will try to add if time allows =D

use ActivityName.this instead of this

CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.start(FaceMatch.this);

Then crop will work on Android 11