我知道有人问过这个问题,但我一直在互联网上寻找解决我问题的正确方法。我使用相机意图,然后尝试从相机获取图像并将其设置为图像视图。一切都很好,直到是时候回去设置图像了。我可以拍照,但是当我单击确定时,它会重新启动应用程序而没有图像。关于如何让它实际捕获图像而不仅仅是重新启动的任何想法?
public class Submit extends Activity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.submit);
this.imageView = (ImageView) this.findViewById(R.id.imageView);
Button photoButton = (Button) this.findViewById(R.id.photoButton);
photoButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}