Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

android - Camera intent for ACTION_IMAGE_CAPTURE does not appear on Samsung Galaxy Nexus(4.0.2)

I use following code take a Picture from camera and to obtain picture's path.

...
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_IMAGE_CAPTURE); // image capture
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult:" + resultCode + " request:" + requestCode);

    switch (requestCode) {
        case CAMERA_IMAGE_CAPTURE:
            Uri selectedImageUri = data.getData();
            userImagePath = getPath(selectedImageUri);
        break;
    }
}

It works good on emulator and on different devices. But on Samsung Galaxy Nexus(4.0.2) it does not launches Camera app. But it returns RESULT_OK to onActivityResult and I see no exceptions in LogCat. Please give me and advice how to solve this issue. Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are missing EXTRA_OUTPUT, which may impact matters. My Galaxy Nexus can run this sample project successfully, which uses the following code to request the picture:

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

output = new File(dir, "CameraContentDemo.jpeg");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));

startActivityForResult(i, CONTENT_REQUEST);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...