wildabeast / BarcodeScanner

Official repository now at [phonegap/phonegap-plugin-barcodescanner](http://github.com/phonegap/phonegap-plugin-barcodescanner).
968 stars 743 forks source link

Nexus 7 / Android 4.1: "the Android camera encountered a problem" #4

Closed FelixSchwarz closed 11 years ago

FelixSchwarz commented 11 years ago

This is a clone of https://github.com/phonegap/phonegap-plugins/issues/866 as I figure that issues should be filed now.

I have installed the Barcode Scanner Phonegap plugin. It works very well except for my nexus 7 tablet with this error message : "Sorry, the Android camera encountered a problem. You may need to restart the device."

I have restarted, but I have still the same problem.

Here is my error message in the logcat console

11-05 11:36:50.197: W/CaptureActivity(5517): java.io.IOException
11-05 11:36:50.197: W/CaptureActivity(5517): at com.google.zxing.client.android.camera.CameraManager.openDriver(CameraManager.java:128)
11-05 11:36:50.197: W/CaptureActivity(5517): at com.google.zxing.client.android.CaptureActivity.initCamera(CaptureActivity.java:606)
11-05 11:36:50.197: W/CaptureActivity(5517): at com.google.zxing.client.android.CaptureActivity.surfaceCreated(CaptureActivity.java:346)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.SurfaceView.access$000(SurfaceView.java:81)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:671)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1820)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.Choreographer.doFrame(Choreographer.java:525)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.os.Handler.handleCallback(Handler.java:615)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.os.Looper.loop(Looper.java:137)
11-05 11:36:50.197: W/CaptureActivity(5517): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-05 11:36:50.197: W/CaptureActivity(5517): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 11:36:50.197: W/CaptureActivity(5517): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 11:36:50.197: W/CaptureActivity(5517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-05 11:36:50.197: W/CaptureActivity(5517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-05 11:36:50.197: W/CaptureActivity(5517): at dalvik.system.NativeStart.main(Native Method)

What should I do ?

Thanks for your answer.

Just to add: I'm seeing the exactly same issue. I suspect an upgrade to the latest zxing version fixes the problem as indicated in the pull request https://github.com/phonegap/phonegap-plugins/pull/654

wildabeast commented 11 years ago

I don't think the zxing client supports devices without rear facing cameras -- as per This discussion and this source code.

I think that is the issue we're seeing here -- that said, I should still update to the latest zxing client.

FelixSchwarz commented 11 years ago

Sorry about the spamming then - from the ml announcement I (wrongly) assumed that the whole repo will be split up (which would be a good thing imho).

Anyway from the source code you linked I don't see why a front-facing camera should not work. The code looks a bit simplistic but at the end of the method they try to open the first camera (which is likely front-facing I assume...). That should actually handle our problem, right?

As a side note: What is the best place to ask some questions the Barcode Scanner plugin? I have questions about upstreaming of certain patches from this repo (non-constant variables in switch/case).

FelixSchwarz commented 11 years ago

Also is there a plan to split up the official phonegap plugins repo? I used your fork because I didn't manage to get the barcode scanner plugin working without pluginstall.

wildabeast commented 11 years ago

Oh, I think you're right about front-facing camera support -- I interpreted the comment about "opening up the possibility of accessing front-facing cameras" to mean it wasn't yet implemented, but that code says otherwise. I'll try to update my repo asap.

I'm thinking the best place to ask questions is the http://github.com/phonegap/phonegap-plugins repo, or possibly the Google Group? As I mentioned in the other thread, I simply yanked out the BarcodeScanner code and restructured it -- I'm not very familiar with the low-level implementations. Keeping it on the plugins repo would hopefully expose your questions to the plugin authors.

I've heard talk about splitting up the repo, but I'm not sure of the official plan -- if you're active on the mailing list then you probably know more than me. But I agree it would be a good thing -- tracking that many projects in one repo doesn't make much sense, vs separate repos and some central registry.

wildabeast commented 11 years ago

Re splitting the phonegap-plugins repo: http://shazronatadobe.wordpress.com/2012/11/07/cordova-plugins-put-them-in-your-own-repo-2/ http://simonmacdonald.blogspot.ca/2012/11/my-phonegap-plugins-have-moved.html

wildabeast commented 11 years ago

Rounding back again -- I don't think that pull request includes the code which supports front-facing cameras. That support appears to have been added since that pull request was opened (see the pull request code vs the latest zxing code.

So the solution is still to update this plugin to the latest zxing code. However this is non-trivial. I'll get to this as soon as I can, which won't be immediately.

FelixSchwarz commented 11 years ago

Thanks for the update - could you outline the process required to update the library (as a start for Android)? I tried to do that on my own but got stuck after fixing several issues (e.g. non-static constants in switch statements).

So for starts I was unsure which files i should copy from the zxing source (I planned on using the latest stable release 2.1). Obviously "core/src" but then it looks like some files are missing which are located in android-integration/src. Should I just copy them over?

wildabeast commented 11 years ago

Well, here's some instructions that I would probably use for updating the Library/ project: https://github.com/hansjorg/phonegap-plugins/blob/master/Android/BarcodeScanner/LibraryProject/README.

In addition to that, we want this plugin to work with pluginstall. If you look at my (short) commit history in this repo, you'll see what I had to do to make this happen.

Note that my Android dev experience is limited -- not one of the dudes that wrote this from scratch.

Pinging @hansjorg in case he's interested

dread45153 commented 11 years ago

Any updates on this? I took a shot at trying to update the library project, but I wasn't able to get it working.

Thanks

mikeymckay commented 11 years ago

Help me too!

Eccenux commented 11 years ago

Could you just expose a boolean value like scannerIsOperational true/false or something like that so that I could check it and avoid my app crashing? That would also allow me to hide a scan button (since it's of no use when scanning doesn't work on certain device for now).

Otherwise I can only check if the device is Nexus 7. Which is kind of lame, as you know, as it is much like checking what kind of browser a user is using rather then checking for real (current) capabilities of it.

Here is a simple check for the camera: http://stackoverflow.com/questions/6098729/android-front-camera?lq=1

Eccenux commented 11 years ago

I have analyzed both repos and have a question. Which repo contains the latest version?

I'm asking because BarcodeScanner\src\android\LibraryProject\ seem to contain older version (3.61 beta 1) then phonegap-plugins\Android\BarcodeScanner\2.2.0\LibraryProject\ (4.3.1).

The problem with the old version of the library (3.61 beta 1) is only partly because it doesn't support front camera. It simply throws an error in openDriver which it doesn't catch at any later stage and so the app crashes. This code is just asking for it ;-)... This seem to also be fixed in 4.3.1.

Eccenux commented 11 years ago

OK. So I had latest LibraryProject tested on Nexus 7 and on HTC Desire HD and all seem to work fine. Not so fine on Nexus 7 but it seems like a problem with low resolution camera. Anyway, I've made a pull request with code and compiled jar.

Please let us know when it will be possible to test this with PG Build. Thanks :-).

wildabeast commented 11 years ago

OK merged the pull request, tagged 0.6.0, and deployed to Build.

https://build.phonegap.com/plugins/13

michelpa commented 10 years ago

Hello,

I reopen this issue because i've got the same error on one device. It had two camera (front and back)...

Any idea?

Tks

drmpf commented 9 years ago

I got the same problem Fixed it with

SurfaceHolder surfaceHolder = surfaceView.getHolder(); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

Note: this seems to be a recent issue with the OS ( pre V3.0 Android) as the code was previously working.

athkalia commented 7 years ago

I had a related problem and it turned out I was missing the Marhmellow runtime permission for camera