Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cordova-plugin-camera: Getting "No Image Selected" error on Android 4.4 device

I'm working on an hybrid mobile app build with Ionic 1.x. Currently I'm dealing with an weird behavior related to cordova-plugin-camera on devices running Android 4.4 (KitKat - Also tested in 4.3). When I run the following code:

var options = {
    quality: 50,
    mediaType: Camera.MediaType.PICTURE,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType: Camera.PictureSourceType.CAMERA,
    allowEdit: false,
    encodingType: Camera.EncodingType.JPEG,
    saveToPhotoAlbum: false,
    correctOrientation: true
};

navigator.camera.getPicture(function (imageData) {
    console.log(imageData);
}, function (err) {
    console.log(err);
}, options);

The error callback is instantly fired and prints "No Image Selected" to console. That is: the camera app is opened and the error callback is fired while the camera is opened, before I take a picture.

But this same code works on devices with new Android versions (tested on an Android 7.0 device).

I'm using:

  • Cordova 8.0
  • cordova-android 6.4.0
  • cordova-plugin-camera 4.0.2

Have tried this solution, but getting the same result. So, how can I solve this issue? Am I forgetting something?

Thanks for the help.

like image 932
Bruno Peres Avatar asked Apr 16 '18 18:04

Bruno Peres


2 Answers

After two days of working on this and 30 minutes after this post on StackOverflow, the issue was solved following the steps described in this GitHub comment:

  1. Add the following line to your config.xml: <preference name="AndroidLaunchMode" value="singleTop" />
  2. Remove the directory platforms/android/
  3. Run ionic cordova prepare android

Seems that the issue is caused by the installation of cordova-plugin-background-mode plugin, which I'm using too.

like image 104
Bruno Peres Avatar answered Nov 07 '22 18:11

Bruno Peres


Fixed Issue by : Add the following line to your config.xml :

< preference name="AndroidLaunchMode" value="singleTop" />

Note : Please check App if you use Appsflyer onelink for deeplinking.

like image 1
Kunal goswami Avatar answered Nov 07 '22 20:11

Kunal goswami