ArthurHub / Android-Image-Cropper

Image Cropping Library for Android, optimized for Camera / Gallery.
Apache License 2.0
6.39k stars 1.38k forks source link

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

Open Raj-spbi opened 3 years ago

Raj-spbi commented 3 years ago

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)

BlackBlind567 commented 3 years ago

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

Canato commented 3 years ago

🚨🚨🚨🚨🚨 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

Canato commented 3 years ago

@Raj-spbi @BlackBlind567 @fmaxx @r4jjin @naveenchoudhary947

sitaram-gupta commented 3 years ago

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

`

    <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>`
Canato commented 3 years ago

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

A guide how to update

sitaram-gupta commented 3 years ago

@Canato Thank you but all is working except Camera.

Canato commented 3 years ago

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.

sitaram-gupta commented 3 years ago

@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?

Canato commented 3 years ago

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

sitaram-gupta commented 3 years ago

@Canato Sure, Thanks!

sitaram-gupta commented 3 years ago

@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 commented 3 years ago

@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

ghost commented 3 years ago

@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.
  4. 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 :)

Canato commented 3 years ago

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

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

ghost commented 3 years ago

@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.

sitaram-gupta commented 3 years ago

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

ghost commented 3 years ago

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.

ghost commented 3 years ago

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.

sitaram-gupta commented 3 years ago

@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.

ghost commented 3 years ago

@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.

sitaram-gupta commented 3 years ago

@r4jjin Please check, I have updated.

hareshmunjapara commented 3 years ago

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

sitaram-gupta commented 3 years ago

Please create issue here! Create Issue

Canato commented 3 years ago

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

hareshmunjapara commented 3 years ago

@Canato i am using java code please solve it

hareshmunjapara commented 3 years ago

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 commented 3 years ago

@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

sitaram-gupta commented 3 years ago

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

ghost commented 3 years ago

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 👍

Canato commented 3 years ago

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

ghost commented 3 years ago

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

abdulmanum commented 2 years ago

use ActivityName.this instead of this

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

Then crop will work on Android 11