我目前正在尝试将相机集成到我的 android 应用程序中并将图片保存在我的设备上;但是,当我拍照时,我无法继续(该应用程序可以运行,但相机镜头冻结意味着我可以再拍一张照片并返回,但无法确认)。我想知道你们是否可以帮忙。请尽可能简单地解释这一点,因为我对 android 编程非常陌生。感谢大家!
public class PhotoCapture extends Activity {
int TAKE_PHOTO_CODE = 0;
public static int count=0;
public static File newfile;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.photocapture);
Button capture = (Button) findViewById(R.id.takepicture);
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ContextWrapper cw = new ContextWrapper(getBaseContext());
newfile = cw.getDir("test.jpg", Context.MODE_PRIVATE);
try {
newfile.createNewFile();
} catch (IOException e) {}
Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
uri = data.getData().toString();
Log.d("CameraDemo", "Pic saved");
Intent myview = new Intent(this, Finalpiece.class);
startActivity(myview);
}
}
}