1

I'm trying to implement SoundCloud's image crop to my app. Here's what I'm doing so far:

call Crop.pickImage((Activity) this) to pick an image

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

    if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
        Uri inputUri = data.getData();
        new Crop(inputUri).output(outputUri).asSquare().start((Activity) context);
    }
    else if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
        Uri cropped = data.getData();
    }
}

At this point I don't know what should be the outputUri. I can just use the same inputUri as the output, but that would overwrite the original image file. I want to create a new file instead. But I can't create new Uri since Android Studio tells me the newly initialized Uri is abstract and can't be used.

Hendra Anggrian
  • 5,780
  • 13
  • 57
  • 97

1 Answers1

0

I used following methods for my cropping image library for URI creation as well. Hopefully it will helps you:

private void fileSaving(){
        String stateEnvironment = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(stateEnvironment)) {
            mFileTemp = ChatUtils.getOutputMediaFile(101);//new File(Environment.getExternalStorageDirectory(), TEMP_PHOTO_FILE_NAME);
        } else {
            mFileTemp = new File(getFilesDir(), sTEMP_PHOTO_FILE_NAME);
        }
    }

    private void takePicture() {

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        try {
            Uri mImageCaptureUri = null;
            String state = Environment.getExternalStorageState();
            if (Environment.MEDIA_MOUNTED.equals(state)) {
                mImageCaptureUri = Uri.fromFile(mFileTemp);
            } else {
                // mImageCaptureUri =
                // InternalStorageContentProvider.CONTENT_URI;
            }
            intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                    mImageCaptureUri);
            intent.putExtra("return-data", true);
            startActivityForResult(intent, mREQUEST_CODE_TAKE_PICTURE);
        } catch (ActivityNotFoundException e) {

        }
    }
Usman Khan
  • 3,739
  • 6
  • 41
  • 89