Skip to content

Instantly share code, notes, and snippets.

@SingAvi
Created August 13, 2020 08:48
Show Gist options
  • Save SingAvi/64ad75a9b06308083de7d5dfdc31a9c9 to your computer and use it in GitHub Desktop.
Save SingAvi/64ad75a9b06308083de7d5dfdc31a9c9 to your computer and use it in GitHub Desktop.
Capture Image And Get Uri
Step 1:
# implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
Step 2 :
# <activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />
Step 3 :
private void chooseImage() {
Intent intent = CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(50,50)
.getIntent(getContext());
startActivityForResult(intent, CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE)
{
CropImage.ActivityResult result = CropImage.getActivityResult(data);
Log.d("ImageCrop", "FETCHED DATA");
if (resultCode == Activity.RESULT_OK)
{
imageUri = result.getUri();
Toast.makeText(getActivity(), imageUri.toString(), Toast.LENGTH_SHORT).show();
imageName.setText("Image Selected");
}
else if(resultCode ==CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE)
{
Exception error = result.getError();
}
else{
Toast.makeText(getActivity(), "You did not choose any prescription", Toast.LENGTH_SHORT).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment