Is com.android.camera.action.CROP not available for Android jelly bean 4.3?

后端 未结 3 1132
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 11:53

I was using com.android.camera.action.CROP for cropping after taking pic using camera.

Below was my code which used to work earlier before 4.3.

Inten         


        
3条回答
  •  无人及你
    2020-12-30 12:37

    Copying the answer from a similar question asked earlier..

    Have you considered just using a library like this one:

    GitHubLink

    I find the com.android.camera.action.CROP can sometimes behave differently from phone to phone and is not always available, so it could cause some problems for you anyway if you are looking to release it.

    UPDATE:

    I have tested the above library with Android 4.3 and it works with no problem. You just need to add the library to your project.

    You can then write your method in a very similar way:

    private void performCrop(Uri picUri) {
    //you have to convert picUri to string and remove the "file://" to work as a path for this library
    String path = picUri.toString().replaceAll("file://", "");
    try {
        int aspectX = 750;
        int aspectY = 1011;
    
        Intent intent = new Intent(this, CropImage.class);
        //send the path to CropImage intent to get the photo you have just taken or selected from gallery
        intent.putExtra(CropImage.IMAGE_PATH, path);
    
        intent.putExtra(CropImage.SCALE, true);
    
        intent.putExtra("aspectX", aspectX);
        intent.putExtra("aspectY", aspectY);
    
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCurrentPhotoPath)));
    
        startActivityForResult(intent, CROP);
    }
    catch (ActivityNotFoundException anfe) {
        String errorMessage = "Your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
    

提交回复
热议问题