我使用的目的是调用相机和onresult来获取拍摄的图像,但如果没有拍摄图像(按下取消时),我想回到我从相机调用相机的屏幕
我现在正在使用它......但是有更好的方法可以做到这一点:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!(data == null || resultCode == 0)) {
if (requestCode == CAMERA_REQUEST) {
photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
} else {
Intent intent = new Intent(ImageUploaderActivity.this,
ImageUploaderActivity.class);
startActivity(intent);
finish();
}
}
答案 0 :(得分:1)
我在我的应用程序中做了类似的事情,这是我的代码:
if (resultCode == RESULT_OK) {
if (data != null) {
//When all was ok
}
} else if (resultCode == RESULT_CANCELED) {
//When it was canceled, when I press a back button while in camera app.
} else {
//Some other result
}