【发布时间】:2016-09-28 06:13:42
【问题描述】:
我正在使用 android 裁剪图像,这是我用于裁剪图像的代码:
private void performCrop() {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
cropIntent.setDataAndType(picUri, "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", 500);
cropIntent.putExtra("outputY", 500);
//retrieve data on return
cropIntent.putExtra("return-data", true);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
} catch (ActivityNotFoundException anfe) {
//display an error message
String errorMessage = "err";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
我在 android 4.2、4.3 上测试过这段代码,没有问题,但在 android 5,6 上,它返回空指针异常,我不知道为什么。
这段代码有什么问题?如何使其与所有版本的 android 兼容?
【问题讨论】:
-
确保您为 Android 6 应用了权限模型
标签: android android-camera android-gallery android-camera-intent