0

在我的代码中,当我取消相机拍摄的图像时......应用程序崩溃并给出您的应用程序已停止的错误..请帮助我如何解决它。如果拍摄的图像是,我希望我的相机返回到我的应用程序取消...这是我的代码:

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);    
}
4

1 回答 1

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); 
    }
}
于 2013-09-24T01:56:13.060 回答