gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:15:42 25 4
gpt4 key购买 nike

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

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

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

最佳答案

这对我有用:

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

关于Android - 无法从 4.2.2 上的相机 Intent 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17085005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com