2013-06-13 52 views
4

我試圖拍照,比獲取文件路徑圖像:Android的 - 未通過調用攝像頭的意圖得到4.2.2

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銀河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); 

工作正常。真的,我不知道爲什麼。

+0

**提供完整的錯誤痕跡**你捕捉即在拍攝意圖只是負載或拍攝圖像後圖像之前觀察崩潰.. – CRUSADER

+0

應用程序崩潰時,它的嘗試從Camera Intent回來。結果中只有空數據。 – goodm

+0

請看[看這個](http://stackoverflow.com/a/11351580/2345913) – CRUSADER

回答

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); 
相關問題