如果要裁剪在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)
现在当它成功返回onActivityResult时,我会收到一个错误提示信息,内容为“无法编辑此图像”。