在我的代码中,当我取消相机拍摄的图像时......应用程序崩溃并给出应用程序已停止的错误。请帮我解决问题。如果我希望我的相机返回我的应用程序,如果拍摄的图像被取消...这是我的代码:
int take_image=1;
buttonCamera.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View view) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, take_image);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == take_image) {
//simple data show for user ease
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imageView2.setImageBitmap(thumbnail);
}
if (requestCode==RESULT_CANCELED){
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
}
答案 0 :(得分:0)
注意requestCode和resultCode,它们是不同的。修改你的代码:
if (requestCode == take_image) {
if (resultCode==RESULT_OK){
//simple data show for user ease
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imageView2.setImageBitmap(thumbnail);
}
else if (resultCode == RESULT_CANCELED) {
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
}
}