I've been trying to implement the Ti Barcode Scanner module into my android app but it keeps crashing when I call the Barcode.capture() method. I tested it on both the emulator and the device itself with the same results.
I am using Titanium 2.1.1.GA and Android 4.1. I made a completely fresh project and used the example code that's included with the module to rule out any errors with my app code. When I run the same code on Android 2.2 and it works fine.
The stack trace seems to show that the error has something to do with zxing, but I am not exactly sure. If anyone could give me a hand with this I would really appreciate it!
Here is the stack trace when the error occurs (after tapping the scan code button in the example):
[ERROR][TiApplication( 743)] (main) [4543,4543] Sending event: exception on thread: main msg:android.content.res.Resources$NotFoundException: String resource ID #0x0; Titanium 2.1.1,2012/07/27 14:01,0fd84a2 [ERROR][TiApplication( 743)] android.content.res.Resources$NotFoundException: String resource ID #0x0 [ERROR][TiApplication( 743)] at android.content.res.Resources.getText(Resources.java:229) [ERROR][TiApplication( 743)] at android.content.res.Resources.getString(Resources.java:313) [ERROR][TiApplication( 743)] at android.content.Context.getString(Context.java:292) [ERROR][TiApplication( 743)] at com.google.zxing.client.android.CaptureActivity.displayFrameworkBugMessageAndExit(CaptureActivity.java:791) [ERROR][TiApplication( 743)] at com.google.zxing.client.android.CaptureActivity.initCamera(CaptureActivity.java:780) [ERROR][TiApplication( 743)] at com.google.zxing.client.android.CaptureActivity.surfaceCreated(CaptureActivity.java:477) [ERROR][TiApplication( 743)] at android.view.SurfaceView.updateWindow(SurfaceView.java:543) [ERROR][TiApplication( 743)] at android.view.SurfaceView.access$000(SurfaceView.java:81) [ERROR][TiApplication( 743)] at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169) [ERROR][TiApplication( 743)] at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:671) [ERROR][TiApplication( 743)] at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1818) [ERROR][TiApplication( 743)] at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998) [ERROR][TiApplication( 743)] at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212) [ERROR][TiApplication( 743)] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) [ERROR][TiApplication( 743)] at android.view.Choreographer.doCallbacks(Choreographer.java:555) [ERROR][TiApplication( 743)] at android.view.Choreographer.doFrame(Choreographer.java:525) [ERROR][TiApplication( 743)] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) [ERROR][TiApplication( 743)] at android.os.Handler.handleCallback(Handler.java:615) [ERROR][TiApplication( 743)] at android.os.Handler.dispatchMessage(Handler.java:92) [ERROR][TiApplication( 743)] at android.os.Looper.loop(Looper.java:137) [ERROR][TiApplication( 743)] at android.app.ActivityThread.main(ActivityThread.java:4745) [ERROR][TiApplication( 743)] at java.lang.reflect.Method.invokeNative(Native Method) [ERROR][TiApplication( 743)] at java.lang.reflect.Method.invoke(Method.java:511) [ERROR][TiApplication( 743)] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) [ERROR][TiApplication( 743)] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) [ERROR][TiApplication( 743)] at dalvik.system.NativeStart.main(Native Method) [ERROR][AndroidRuntime( 743)] FATAL EXCEPTION: main [ERROR][AndroidRuntime( 743)] android.content.res.Resources$NotFoundException: String resource ID #0x0 [ERROR][AndroidRuntime( 743)] at android.content.res.Resources.getText(Resources.java:229) [ERROR][AndroidRuntime( 743)] at android.content.res.Resources.getString(Resources.java:313) [ERROR][AndroidRuntime( 743)] at android.content.Context.getString(Context.java:292) [ERROR][AndroidRuntime( 743)] at com.google.zxing.client.android.CaptureActivity.displayFrameworkBugMessageAndExit(CaptureActivity.java:791) [ERROR][AndroidRuntime( 743)] at com.google.zxing.client.android.CaptureActivity.initCamera(CaptureActivity.java:780) [ERROR][AndroidRuntime( 743)] at com.google.zxing.client.android.CaptureActivity.surfaceCreated(CaptureActivity.java:477) [ERROR][AndroidRuntime( 743)] at android.view.SurfaceView.updateWindow(SurfaceView.java:543) [ERROR][AndroidRuntime( 743)] at android.view.SurfaceView.access$000(SurfaceView.java:81) [ERROR][AndroidRuntime( 743)] at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169) [ERROR][AndroidRuntime( 743)] at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:671) [ERROR][AndroidRuntime( 743)] at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1818) [ERROR][AndroidRuntime( 743)] at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998) [ERROR][AndroidRuntime( 743)] at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212) [ERROR][AndroidRuntime( 743)] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) [ERROR][AndroidRuntime( 743)] at android.view.Choreographer.doCallbacks(Choreographer.java:555) [ERROR][AndroidRuntime( 743)] at android.view.Choreographer.doFrame(Choreographer.java:525) [ERROR][AndroidRuntime( 743)] at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
1 Answer
I found what the problem was and a workaround!
For anyone else having issues with the Barcode Scanner module on the Nexus 7 here's what seems to be the real issue. The Nexus 7 doesn't have a rear facing camera only a front facing one. The android OS thinks that if a device doesn't have a rear camera it just doesn't have a camera at all, and it apparently won't check for a front one if a rear one isn't found.
So if you need to get the barcode scanning working on the Nexus 7, it is just a matter of going into the timodule.xml file and adding android:required='false' to any line that says uses-feature or uses-permission for the camera. Then you'll need to create some kind of check for the nexus 7 and put this line Barcode.useFrontCamera = true; when you declare your Barcode scanner.
I may have it slightly easier than some with this problem since I am developing my app exclusively for the nexus 7, but I thought I would follow up with my findings all the same.
Your Answer
Think you can help? Login to answer this question!