Java Code Examples for com.theartofdev.edmodo.cropper.CropImage#PICK_IMAGE_CHOOSER_REQUEST_CODE

The following examples show how to use com.theartofdev.edmodo.cropper.CropImage#PICK_IMAGE_CHOOSER_REQUEST_CODE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PickImageActivity.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // handle result of pick image chooser
    if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        Uri imageUri = CropImage.getPickImageResultUri(this, data);

        if (presenter.isImageFileValid(imageUri)) {
            this.imageUri = imageUri;
        }

        // For API >= 23 we need to check specifically that we have permissions to read external storage.
        if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {
            // request permissions and handle the result in onRequestPermissionsResult()
            requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
        } else {
            // no permissions required or already grunted
            onImagePikedAction();
        }
    }
}
 
Example 2
Source File: PickImageActivity.java    From social-app-android with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // handle result of pick image chooser
    if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        Uri imageUri = CropImage.getPickImageResultUri(this, data);

        if (presenter.isImageFileValid(imageUri)) {
            this.imageUri = imageUri;
        }

        // For API >= 23 we need to check specifically that we have permissions to read external storage.
        if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {
            // request permissions and handle the result in onRequestPermissionsResult()
            requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
        } else {
            // no permissions required or already grunted
            onImagePikedAction();
        }
    }
}
 
Example 3
Source File: MainActivity.java    From Android-Image-Cropper with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressLint("NewApi")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE
      && resultCode == AppCompatActivity.RESULT_OK) {
    Uri imageUri = CropImage.getPickImageResultUri(this, data);

    // For API >= 23 we need to check specifically that we have permissions to read external
    // storage,
    // but we don't know if we need to for the URI so the simplest is to try open the stream and
    // see if we get error.
    boolean requirePermissions = false;
    if (CropImage.isReadExternalStoragePermissionsRequired(this, imageUri)) {

      // request permissions and handle the result in onRequestPermissionsResult()
      requirePermissions = true;
      mCropImageUri = imageUri;
      requestPermissions(
          new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
          CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
    } else {

      mCurrentFragment.setImageUri(imageUri);
    }
  }
}
 
Example 4
Source File: FlutterImagePickCropPlugin.java    From FlutterImagePickCrop with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {
                Uri resultUri = result.getUri();
                finishWithSuccess(resultUri.getPath());
            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                Exception error = result.getError();
                finishWithError("Failed Permission",error.getMessage());
            }

            return true;
        }

    if (requestCode == CropImage.PICK_IMAGE_CHOOSER_REQUEST_CODE && resultCode == RESULT_OK) {
            Uri imageUri = CropImage.getPickImageResultUri(context, data);
            if (CropImage.isReadExternalStoragePermissionsRequired(context, imageUri)) {
                mCropImageUri = imageUri;
                //Toast.makeText(activity, "check: " + mCropImageUri.toString(), Toast.LENGTH_SHORT).show();
                activity.requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CropImage.PICK_IMAGE_PERMISSIONS_REQUEST_CODE);
            } else {
                startCropImageActivity(imageUri);
            }


            return true;
        }
//
//        else if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
//            Uri imageUri = CropImage.getPickImageResultUri(context, data);
//            if (imageUri != null) {
//                finishWithSuccess(imageUri.getPath());
//            }else {
//                finishWithSuccess(null);
//            }
//            return true;
//        }

        return false;
    }