简体   繁体   中英

Android bug: Crop intent works on some devices

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM