我正在制作一款应用程序,当活动被创建时,我会运行相机意图。问题是,当我点击拍摄的图片后的“确定”按钮时,它只会再次打开相机来拍照。以下是代码:taken从另一个活动中设置为false。我可以确认,在此活动开始时,taken为false。
public class QuickEditActivity extends Activity {
public static boolean taken;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quickedit);
if(!QuickEditActivity.taken) {
RunCam();
}
}
private void RunCam() {
QuickEditActivity.taken = true;
Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camIntent,1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data != null && data.getExtras() != null) {
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
if(bitmap != null) {
ImageView imgView = (ImageView)findViewById(R.id.CamView);
imgView.setImageBitmap(bitmap);
}
else
{
this.finish();
}
}
else {
this.finish();
}
super.onActivityResult(requestCode, resultCode, data);
}
}