Capturing a camera image does not return data - on some devices (devices)

I started testing my application on the Moto E2, which is one of the first Android Lollipop devices on the marked ones. It turns out that I suddenly have a problem with capturing images using the camera . I can not get the image.

Create an image capture target using:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, PICK_FROM_CAMERA);

Upon returning to my activity Intentdoes not contain data, i.e. data.getData()returns null.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode != RESULT_OK) return;

    switch(requestCode) {
        case PICK_FROM_CAMERA:
        (...)
    }
}

Moto E2 runs Android 5.0.2: enter image description here

SO . , , Android, KitKat Jelly Bean (. ). ?

Galaxy S4 mini Android 4.4.2: enter image description here

+4
3

Android 5.0 Intent. , , . , Camera API 5.0

static final int REQUEST_IMAGE_CAPTURE = 1;

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
}

Android 5.0 API.

https://developer.android.com/training/camera/photobasics.html#TaskCaptureIntent

+1

Jibran Khan ( Android https://developer.android.com/training/camera/photobasics.html#TaskCaptureIntent).

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
    // Create the File where the photo should go
    File photoFile = null;
    try {
        photoFile = createImageFile();
    } catch (IOException ex) {
        // Error occurred while creating the File
        ...
    }
    // Continue only if the File was successfully created
    if (photoFile != null) {
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(photoFile));
        startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
    }
}

String mCurrentPhotoPath;

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
        imageFileName,  /* prefix */
        ".jpg",         /* suffix */
        storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}

mCurrentPhotoPath onActivityResult().

data, .

+2

I also had some problems with the camera’s intention on different Android devices of different Android manufacturers and versions (see the original message here: Summary: take a picture using the camera’s intention and show the photo with the correct orientation (works on all devices) )

I posted my code on github: https://github.com/ralfgehrer/AndroidCameraUtil

+2
source

Source: https://habr.com/ru/post/1583825/


All Articles