简体   繁体   English

拍照后onActivityResult data.getData()返回null

[英]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.

相关问题 android onactivityresult data.getData()在片段中返回null - android onactivityresult data.getData() returns null in a fragment data.getData()在从相机和图库中选择/选择图片时在OnActvityResult中返回null - data.getData() returns null in OnActvityResult while taking /Selecting Pictures from Camera and Gallery data.getData()有时会返回null - data.getData() sometimes returns null Android getAbsolutePath(data.getData())始终返回null - Android getAbsolutePath(data.getData()) always returns null 对于某些手机,Android data.getData() 从 CameraActivity 返回 null - Android data.getData() returns null from CameraActivity for some phones onActivityResult 返回 Intent data.getData(); 始终为 Null 仅在 Marshmallow 和 Lollipop 中 - onActivityResult returning Intent data.getData(); always Null Only in Marshmallow and Lollipop 在OnActivityResult()中调用data.getData时出现NullPointerException? - NullPointerException when calling data.getData inside OnActivityResult()? Gallery intent.getData()在onActivityResult中返回null - Gallery intent.getData() returns null in onActivityResult Camera的onActivityResult数据为null - onActivityResult data null with Camera 相机 Intent 返回 null onActivityResult - Camera Intent returns null onActivityResult
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM