简体   繁体   English

Android:Camera Crop意图Lollipop及以上提供Toast消息,因为此图像不支持编辑

[英]Android:Camera Crop intent Lollipop and above giving toast message as Editing isn't supported for this image

For Cropping images taken from android phone in Lollipop and above One should use File Provider here is my code. 对于从Lollipop及以上的Android手机拍摄的裁剪图像应该使用文件提供程序这里是我的代码。

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.example.test.fileprovider"
            android:grantUriPermissions="true"
            android:exported="false"
            >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths"
                />

        </provider>

<paths>
    <external-path name="myexternalimages" path="dcim/ProfileImage/"/>
</paths>





 final  Uri providedUri = FileProvider.getUriForFile(ProfileUpdateActivity.this,
                    "com.example.test.fileprovider", imageUpLoadFile);
            Intent cropIntent = new Intent("com.android.camera.action.CROP");



            //indicate image type and Uri
            cropIntent.setDataAndType(providedUri, "image/*");
            //set crop properties
            cropIntent.putExtra("crop", "true");
            //indicate aspect of desired crop
            cropIntent.putExtra("aspectX", 1);
            cropIntent.putExtra("aspectY", 1);
            //indicate output X and Y
            cropIntent.putExtra("outputX", 256);
            cropIntent.putExtra("outputY", 256);
            //retrieve data on return
            cropIntent.putExtra("return-data", true);

            // Exception will be thrown if read permission isn't granted
            cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            startActivityForResult(cropIntent, PIC_CROP);

where imageUploadFile =/storage/emulated/0/dcim/ProfileImage/IMG_20160330_134823_1697877403.png (Example)

Now When it returns successfully onActivityResult it I get an error toast message as Editing this image is not available 现在当它成功返回onActivityResult时,我收到错误的Toast消息,因为编辑此图像不可用

Adding EXTRA_OUTPUT to the intent fixed it for me. 添加EXTRA_OUTPUT到意图修复它为我。

cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, providedUri);  

But make sure to also add write uri permission to the Intent. 但是请确保还向Intent添加了写uri权限。
So that the Camera app can write the cropped image to the provided Uri. 这样Camera应用程序就可以将裁剪后的图像写入提供的Uri。

cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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