使用相机Android拍照在Eclipse中获取错误

时间:2012-12-30 11:38:47

标签: android image

Eclipse在以下代码中给出了TAKE_PICTURE错误。我尝试用CAMERA_PIC_REQUEST替换它并得到了同样的错误。我在这里开发Android 4.2。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    File file = new File(Environment.getExternalStorageDirectory(), "test.jpeg");
    Uri outputFileUri = Uri.fromFile(file);

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

    startActivityForResult(intent, TAKE_PICTURE);
}

任何想法我必须做什么?

1 个答案:

答案 0 :(得分:0)

我想这是你从某个地方复制的不完整的示例代码,startActivityForResult函数接收一个随意的请求代码,稍后你的应用程序将使用它来找出刚刚完成的活动,如下所示:

startActivityForResult(i, 100);
...    

startActivityForResult(i, 200);
...

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 100){
        //First Activity has just finished
    }
    if (requestCode == 200){
        //Second Activity has just finished
    }
}

基本上,您应该在应用程序中为TAKE_PICTURE定义一个任意值。