Android - 无法从4.2.2获取相机意图的图像

时间:2013-06-13 10:40:31

标签: android android-camera nexus-10

我正在尝试拍照而不是通过调用来获取文件路径:

Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera_intent, Static.TAKE_PICTURE);

而不是:

case Static.TAKE_PICTURE:
if(resultCode == Activity.RESULT_OK){  
    if(data.getData() != null){
        Uri selectedImage = data.getData();
        String path = selectedImage.getPath();
        if(path.contains("images/media")){
            path = Static.getImageRealPathFromURI(getActivity().getBaseContext(),selectedImage);
        }
    }
}
break;

在4.1.2 Galaxy S3上正常工作,但每次都在4.2.2 Nexus 10上崩溃:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65642, result=-1, data=null} to activity {com.******.***/com.******.***.Main}: java.lang.NullPointerException

如果我尝试为视频做同样的事情:

Intent video_intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(video_intent, Static.RECORD_VIDEO);

工作正常。真的,我不知道为什么。

1 个答案:

答案 0 :(得分:0)

这对我有用:

photoFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Static.genereateFileName() + ".jpg";  
File imageFile = new File(photoFilePath); 
Uri imageFileUri = Uri.fromFile(imageFile);

Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera_intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri); 
startActivityForResult(camera_intent, Static.TAKE_PICTURE);