Phonegap-plugin-barcodescanner: Problem with Android 6.0.1

Created on 4 Jan 2016  路  27Comments  路  Source: phonegap/phonegap-plugin-barcodescanner

I get an error on Android 6.0.1 saying that there was an error with the "Android Camera", (the message is in German, but it may translate to:

Unfortunately there was an error with the Android-Camera. It could be that you need to restart your device.

Does anyone see this?

bug android6

Most helpful comment

For Android 6+, because of the "permission" issue, If you got the message "Sorry, the camera encountered a problem. You may need to restart the device.", go to Settings - Apps - find "your app name" - select Permissions and switch on "Camera".

All 27 comments

I created an app using this same plugin but it's only works in android 4, I tested my app on android 5.1.1 and android 6.0.1, but it's not doing anything on a scan button click. Not opening the camera. Even I found none of my functions are working on those platform.

Also I found following link, which may be help you:
https://cordova.apache.org/announcements/2015/11/09/cordova-android-5.0.0.html

I have the same error in Android 6.x.x. Unfortunately there was an error with the Android-Camera. It could be that you need to restart your device. Till Android 5.x.x, it's working but not for the Android 6.

So how can I test with this Android zxing integration? I am totally new to this. What steps I need to follow?

Sicerely

For me, this problem only shows when I add the facebook4 plugin (https://www.npmjs.com/package/cordova-plugin-facebook4).

If I remove this from my package, the camera starts working again. I'm not sure if that's a compatibility problem on the fb plugin side, or on this plugins side...

I am also facing this problem. I was developing an app with an Android Lollipop phone as test device and the scanner was working, after the update to marshmallow it throws the noted error. Also updated to the latest cordova, android platform with no success. Any temporal fixes or work arounds?

A potential workaround is to change your target sdk version to 22 (Lollipop) instead of 23 (Marshmallow).
In platforms/android/AndroidManifest.xml change to:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />

In platforms/android/prodject.properties change to:

target=android-22

I had the same problems as above. Updated cordova to 6, Cordova Android to 5.1 and nothing worked. Then I dowgraded my sdk and that fixed it. Building to Android 5 and Android 6 devices with the old sdk works fine.

Thanks for the suggestion @vdamyanov!

I'm regenerating the platform directories as part of our build process, so I added the config to our config.xml:

<platform name="android">
        <preference name="android-targetSdkVersion" value="22"/>
</platform>

Seems to have done the trick for now!

Same here. Cannot get it to work when installing with VS 2015 with TACO update 7. I am deploying it on a nexus 6p. Used to work before getting the latest TACO update.

I had the same Problem. I looked in the link from @vrushankshukla and like it says I updated my Android version with cordova platform update [email protected].
That fixed the problem on my Nexus 7 with Android 6.

For Android 6+, because of the "permission" issue, If you got the message "Sorry, the camera encountered a problem. You may need to restart the device.", go to Settings - Apps - find "your app name" - select Permissions and switch on "Camera".

I have the same problem here. It's related to the new Android 6 (API 23) permissions. Setting the targetSdkVersion to "22" solves the problem for now, but this should be fixed.

This is the exception in logcat:
W/ServiceManager: Permission failure: android.permission.CAMERA from uid=10293 pid=1417
E/CameraService: Permission Denial: can't use the camera pid=1417, uid=10293
com.ionicframework.fm176018 W/CameraBase: An error occurred while connecting to camera: 0
com.ionicframework.fm176018 W/CaptureActivity: Unexpected error initializing camera java.lang.RuntimeException: Fail to connect to camera service

Any progress on this?

@loyalpocket : I need to set that exact permission u specified Programatically.. is it possible?????

I got the same issue. This permission in Android 6 needs to be set programmatically before compiling the app. Any one knows where it could be set for this matter?

Is there any official fix for this yet?

I got a fix by installing a plugin:

https://github.com/dpa99c/cordova-diagnostic-plugin#requestcameraauthorization

with requestCameraAuthorization() function

You gotta detect the user Android OS version then call this plugin when it's greater than 6.0 to pop up system native permission so that the user can interact with your app to allow or deny. This action can't be overridden programatically.

For more info. regarding to this matter, follow the link from Google:

http://developer.android.com/training/permissions/requesting.html

Hope this help.

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />

Is helped me to solve my issue. Thank You :)

This plugin work with me.
https://github.com/dpa99c/cordova-diagnostic-plugin#requestcameraauthorization
It's android device permissions problem.

I solved this with https://github.com/NeoLSN/cordova-plugin-android-permission by checking (and requesting /if needed/) permissions in my onDeviceReady callback. It's all about android 6 requests permissions at runtime not during the installation.

Is there any new plugin available?

_edit_: Just saw, @robertklein already suggested that already.

Another proper fix to this problem, without changing the plugin at all, is to use another, more general Android permissions plugin and request the CAMERA permission from your javascript like this:

var permissions = cordova.plugins.permissions;
permissions.hasPermission(permissions.CAMERA, checkPermissionCallback, null);

function checkPermissionCallback(status) {
  if(!status.hasPermission) {
    var errorCallback = function() {
      console.warn('Camera permission is not turned on');
    }

    permissions.requestPermission(
      permissions.CAMERA,
      function(status) {
        if(!status.hasPermission) errorCallback();
      },
      errorCallback);
  }
}

That works good for me, as I have to stay on 3.1.0 of this scanner plugin because all the newer versions have awful QR detection rates/speeds.

After lower the SDK version to 22,

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />

also not working for me? Any other solution is there?

I commented the solution just above ur post

I am getting the same issue, i designed a audio recorder app it works good in lolli-pop, kit-kat and in naugat but that same is not working in marshmallow, i use cordova media plugin

cordova-plugin-compat 1.1.0 cordova-plugin-console 1.0.5 cordova-plugin-device 1.1.4 cordova-plugin-file 4.3.2 cordova-plugin-file-transfer 1.6.2 cordova-plugin-media 3.0.0 cordova-plugin-splashscreen 4.0.2 cordova-plugin-statusbar 2.2.1 cordova-plugin-whitelist 1.3.1 cordova-sqlite-storage 2.0.2 ionic-plugin-keyboard 2.2.1

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />

could someone help me.

I confirm the issue and being solved by downgrading/changing the SDK version. In my case, from 23 to 22.

In my case, I require to use cordova-plugin-barcodescanner and camera. The first one just throws an alert, the second one asks for screen overlap permission (which is granted, but Android doesnt care anyways).

config.xml

<platform name="android">
        <preference name="android-targetSdkVersion" value="22"/>
</platform>

Guess it's the camera permission setting for the application(allowing to use the camera). it worked for Samsung edge(Android 7)

I met same the problem in cordova, and I think phonepgap also run same cordova,
I fix in cordova by install plugin cordova-plugin-android-permissions, then request
permission accessing camera to device with :
var permissions = cordova.plugins.permissions;
permissions.requestPermission(permissions.CAMERA, success, error);

after request permisson , u can check permission access camera and if it has no problem.
device would be scan with :
function success( status ) {
if( !status.hasPermission ) error();
cordova.plugins.barcodeScanner.scan(......)
}

This thread has been automatically locked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

camilonos77 picture camilonos77  路  7Comments

McOffsky picture McOffsky  路  7Comments

front-stream picture front-stream  路  7Comments

thomas-tran picture thomas-tran  路  9Comments

vespino picture vespino  路  9Comments