Android 7.1 (Google Pixel) Camera plugin broken?

Hi, I’ve just recently started working with the new Google Pixel for testing my Ionic 2 Projects, and I’ve come across something peculiar.

When trying to capture a picture using the following:

......

import { Camera } from 'ionic-native';

......

Camera.getPicture({
    quality : 75,
    destinationType : 0,
    sourceType : 1,
    allowEdit : true,
    targetWidth: 300,
    targetHeight: 300,
    saveToPhotoAlbum: false
}).then(imageData => {
    this.base64Image = 'data:image/jpeg;base64,' + imageData;
    console.log(this.base64Image);
}, error => {
    console.log("ERROR -> " + JSON.stringify(error));
});

......

The Application crashes, causing an error:

ERROR → “file:///storage/emulated/0/Android/data/com.ionicframework.ionicApp144916/cache/.Pic.jpg exposed beyond app through ClipData.Item.getUri()”

Now from the devices I have access to, I have come to the conclusion that this error only occurs on the newer Android Nougat device as it works fine on the other devices I have which are running older versions of Android.

After some looking around, I discovered that the ‘file://’ destination is no longer usable in Android Nougat, because of Security issues.

So the easy fix would be to change:

destinationType : 0,

to something else right?.. Well not quite.

I have tried all 3 possible destinationType’s, and all return the exact same error. It’s almost as if Android is totally ignoring the the destinationType option, and just defaulting to ‘file://’, which isn’t even allowed anymore… I’m so confused…

Does anyone out there know a way around this so I can store the photo’s using ‘content://’ rather than ‘file://’ perhaps?

4 Likes

Hmm I dont have android 7.1 or a pixel to test (sadly), so I’ll have to ask around for testers.
In the mean time it might be worth looking around the cordova issue tracker.
Not sure if this is something they’ve seen, but they’d be the proper place to report it.

https://issues.apache.org/jira/browse/CB-12205?jql=project%20%3D%20CB

I have a Nexus 4 with Android 7.1 (Cyanogenmod) and I can confirm this issue.

1 Like

Nexus 5X.
I confirm this issue. cordova camera plugin was working great before uptating my android

Samaung Galaxy S7 - android 7.0 - same issue :’(

I also have this problem on a Motorola G4 on 7.0

Same issue… Anyone found solution?

@guerson I’ve got a Nexus 5X with Android 7.1 and doesn’t face the problem. Do you still face it?

I still have the issue with a Nexus 5X running Android 7.1.2.

My app is using cordova-plugin-camera 2.4.0.

@gentlemanjohn I’ve got same configuration, a Nexus 5X updated to Android 7.1.2 with cordova-plugin-camera 2.4.0, and it seems I don’t face the error

I do like following (if that could help) with ionic-navive 3:

let popoverOptions: CameraPopoverOptions = {
        x: 0,
        y: 0,
        width: 640,
        height: 640,
        arrowDir: this.camera.PopoverArrowDirection.ARROW_ANY
    };

let options: CameraOptions = {
        quality: this.RESOURCES.PHOTO.JPG_QUALITY,
        destinationType: this.camera.DestinationType.FILE_URI,
        sourceType: this.camera.PictureSourceType.CAMERA,
        allowEdit: false,
        encodingType: this.camera.EncodingType.JPEG,
        targetWidth: 640,
        targetHeight: 640,
        mediaType: this.camera.MediaType.PICTURE,
        correctOrientation: true,
        saveToPhotoAlbum: false,
        cameraDirection: this.camera.Direction.BACK,
        popoverOptions: popoverOptions
    };

 this.camera.getPicture(options).then((imageURI: string) => {
    // Here handle the image
  }, (err: string) => {
    // Here handle errors
 });

I am not even using camera plugin but still i am not able to install the app. It fails to install. It happens only on android 7 and above Can anyone help ?

So I found that the camera works just fine on a real build. The issue only crops up in Ionic View. A minor inconvenience. Thanks for the help.

1 Like

I am having this same issue and it appears that it has to with the allowEdit option. If it is true the app crashes if false works just fine. Update: Just figured a solution, if allowEdit needs to be true added saveToPhotoAlbum to true. Now it works

1 Like

Did anyone see if there was a Jira tracking this issue in either cordova general or the camera plugin?
Does anyone there know this is broken?

That didn’t work for me, having the camera as the source causes to crash, saveToPhotoAlbum is true, as is allowEdit. If I set allowEdit to false then nothing happens at all, no crash, no camera interaction.
Choosing the photolibrary as a source works fine, just trying to take a photo.
Problem on both Pixel (Android 7.1.2) and Motorola G4+ (Android 7.0.0)

i am also getting a error even i click ok to process the image.
error" Cancelling camera"
Moto G5…
same code is working in lollipop

Hi, try changing the android-targetSdkVersion to version 23 in the config.xml file.

The plugin seems to be working OK again for me since 2.4.1

Also having this problem on Xiaomi Mi6 (Android version 7.1.1). Is this still an issue for most people?

Not working with android-targetSdkVersion set to 23. Also not working with setting allowEdit and saveToPhotoAlbum to true.

Updating cordova-plugin-camera and cordova-plugin-compat to the latest version (2.4.1 and 1.1.0, respectively) solved the problem of camera not being called up.