简体   繁体   中英

onActivityResult data.getData() returns null after taking camera shot

My phone is 4.2.2. Im running android studio

on my 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.

I got with succes the data.getdata() value when taking shot with my samsung galaxy S4 4.2.2. I realized debugging that the data.getData() comes with : content://media/external/images/media/2846

How can I fix this ?

The fullCameraActivityPath has to be URI. I was passing the path parameter as String. thats the bug......

intent.putExtra(MediaStore.EXTRA_OUTPUT, fullCameraActivityPath);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM