private static final int PHOTO_REQUEST_TAKEPHOTO = 1; 拍照
private static final int PHOTO_REQUEST_GALLERY = 2; 从相册中选择
private static final int PHOTO_REQUEST_CUT = 3; 结果
private File tempFile = new File(Environment.getExternalStorageDirectory(),
getPhotoFileName());
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PHOTO_REQUEST_TAKEPHOTO 当选择拍照时调用
startPhotoZoom(Uri.fromFile(tempFile));
break;
case PHOTO_REQUEST_GALLERY 当选择从本地获取图片时
做非空判断,当我们觉得不满意想重新剪裁的时候便不会报异常,下同
if (data != null) {
startPhotoZoom(data.getData());
} else {
}
break;
case PHOTO_REQUEST_CUT 返回的结果
if (data != null)
setPicToView(data);
sentPicToNext(data);
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
使用系统当前日期加以调整作为照片的名称
private String getPhotoFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat(
'IMG'_yyyyMMdd_HHmmss);
return dateFormat.format(date) + .jpg;
}