Android bug: Crop intent works on some devices

2019-05-30 10:09发布

问题:

Android bug: Crop intent works on some file managers.

Following code:

Launch intent to crop image from folder/file.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        //intent.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
        intent.putExtra("crop", "true");
        intent.putExtra("return-data", true);

        startActivityForResult(intent, 0);

2 versions of code crash differently on different devices, same Android version.

1st verison:

try 
    {
        bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), targetUri);

        }catch (FileNotFoundException e){e.printStackTrace();} 
        catch (IOException e){e.printStackTrace();}

Second version (works on other devices)

bitmap = (Bitmap) data.getExtras().get("data");

What am I suppose to do?

回答1:

The com.android.camera.action.CROP is part of the internal API so it is not guaranteed to be supported by all Android devices.

You will have to implement your own crop activity if you want it to be supported by all devices. At the very least you should implement some sort of fallback behavior if some device does not support the Intent. PLEASE DON'T FORGET TO DO THIS!! :)

And by the way, if I recall correctly, the Samsung Galaxy implements its own Media/Gallery app, so that is why it is failing to recognize the Intent.