I am developing an Android project. In my project, I want to add crop image feature. So I used this library, https://github.com/jdamcd/android-crop. But when I use it. It is giving me error.
This is how I installed:
I put this in grandle, compile 'com.soundcloud.android:android-crop:1.0.1@aar'
I put this in manifest file,
This is how I am using in code:
I open Image picker like this
Crop.pickImage(CurrentActivity.this, IMAGE_CHOOSER_REQUEST_COODE);
In onActivityResult, I am doing like this
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode==IMAGE_CHOOSER_REQUEST_COODE && resultCode == RESULT_OK) { Crop.of(data.getData(),null).asSquare().start(CreateItemActivity.this); } else if(requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) { Uri filePath = data.getData(); } }
But after I crop the image and I click "OK", the result of the activity is not equal to OK. So I cannot retrieve cropped image data.
So I removed
resultCode==RESULT_OK
and I retrieved like this:if(requestCode == Crop.REQUEST_CROP) { Uri filePath = data.getData(); }
Data is always null. What is wrong with my code and how can I fix it?
Add this in
build.gradle
fileMake the layout of Image like this
MainActivity.java
for more detail visit this : https://github.com/edmodo/cropper