[英]onActivityResult data.getData() returns null after taking camera shot
My phone is 4.2.2. 我的电话是4.2.2。 Im running android studio
我正在运行Android Studio
on my mainActivity : 在我的mainActivity上:
startActivityForResult(new CameraStuff().createCustomDialogCamGallery(this,
getCurrentPhotoPath()), REQUEST_IMAGE_OPTIONS);
My code to show a custom dialog is : 我显示自定义对话框的代码是:
public Intent createCustomDialogCamGallery(Activity activity,String fullCameraActivityPath){
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
if(!checkCam(activity).equals(NO_CAM)) {
final Intent captureIntent = new Intent(android.provider.MediaStore
.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = activity.getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities
(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res
.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fullCameraActivityPath);
cameraIntents.add(intent);
}
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_PICK);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Foto");
// Add the camera options.
if(!checkCam(activity).equals(NO_CAM)) {
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new
Parcelable[cameraIntents.size()]));
}
return chooserIntent;
A custom dialog opens with Camera and gallery options. 将打开一个自定义对话框,其中包含照相机和图库选项。 When I choice the camera and take a shot :
当我选择相机拍摄时:
I got null on data.getData() in the onActivityResult when taking shot with my smaller android 4.2.2 phone. 使用较小的android 4.2.2手机拍摄时,onActivityResult中的data.getData()为空。
I got with succes the data.getdata() value when taking shot with my samsung galaxy S4 4.2.2. 使用三星银河S4 4.2.2拍摄时,我成功获得了data.getdata()值。 I realized debugging that the data.getData() comes with : content://media/external/images/media/2846
我意识到调试data.getData()附带了:content:// media / external / images / media / 2846
How can I fix this ? 我怎样才能解决这个问题 ?
The fullCameraActivityPath has to be URI. fullCameraActivityPath必须为URI。 I was passing the path parameter as String.
我将path参数传递为String。 thats the bug......
多数民众赞成在错误......
intent.putExtra(MediaStore.EXTRA_OUTPUT, fullCameraActivityPath);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.