我使用一個 intent 去調用 camera 程序可以得到捕獲的圖像。但是如果圖像沒有捕獲到(取消按鈕按下的情況下),我想馬上返回到調用 camera 程序的那個畫面,有更好的方法可以實現嗎?
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();
}
}
我之前遇見過這個問題是這樣解決的:
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
}