Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Problem with Android 6.0.1 #139

Closed
p-schuler opened this issue Jan 4, 2016 · 27 comments
Closed

Problem with Android 6.0.1 #139

p-schuler opened this issue Jan 4, 2016 · 27 comments

Comments

@p-schuler
Copy link

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?

@vrushankshukla
Copy link

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

@vrushankshukla
Copy link

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

@p-schuler
Copy link
Author

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

@VicM
Copy link

VicM commented Jan 15, 2016

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?

@vdamyanov
Copy link

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.

@poshaughnessy
Copy link

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!

@waelkdouh
Copy link

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.

@lholznagel
Copy link

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.

@loyalpocket
Copy link

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".

@cuiti
Copy link

cuiti commented Mar 28, 2016

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

@rudza
Copy link

rudza commented Apr 8, 2016

Any progress on this?

EddyVerbruggen added a commit to Telerik-Verified-Plugins/BarcodeScanner that referenced this issue Apr 16, 2016
Image upside down on tablet #20
Android UI doesn't support Portrait and is small #4
Prebuilt Zebra Crossing (xzing) Library #3
Forcing landscape on camera android #17

And also fixes these issues found here (possibly others as well):
Android Nexus 5x upside down images phonegap/phonegap-plugin-barcodescanner#175
Support Aztec for Android and Ios phonegap/phonegap-plugin-barcodescanner#195
Android: Force landscape orientation? phonegap/phonegap-plugin-barcodescanner#177
Android M issues. Due to new intent/permissions phonegap/phonegap-plugin-barcodescanner#167
Problem with Android 6.0.1 phonegap/phonegap-plugin-barcodescanner#139
Is the zxing version used years away from the original zxing lib? phonegap/phonegap-plugin-barcodescanner#124
Updating ZXing Library phonegap/phonegap-plugin-barcodescanner#59
@M-k-03
Copy link

M-k-03 commented Apr 25, 2016

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

@azn1viet
Copy link

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?

@lx4r
Copy link

lx4r commented Apr 27, 2016

Is there any official fix for this yet?

@azn1viet
Copy link

azn1viet commented Apr 27, 2016

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.

@Smohanapriya
Copy link

Smohanapriya commented Jul 15, 2016

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

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

@poychang
Copy link

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

@robertklein
Copy link

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.

@Smohanapriya
Copy link

Is there any new plugin available?

@pke
Copy link

pke commented Oct 13, 2016

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.

@Smohanapriya
Copy link

Smohanapriya commented Oct 24, 2016

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?

@pke
Copy link

pke commented Oct 24, 2016

I commented the solution just above ur post

@yokeshvaradhan
Copy link

yokeshvaradhan commented Mar 22, 2017

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.

@alherrera42
Copy link

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>

@koshypcherian
Copy link

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

@hoachan
Copy link

hoachan commented Jul 11, 2017

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(......)
}

@lock
Copy link

lock bot commented Jun 8, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests