Wednesday, October 10, 2012

Barcode Scanner Example Projects

For some reason a lot of folks have trouble setting up the BarcodeScanner Plugin. I've just posted two zip files to my Dropbox account.


1) Barcode scanner library project
2) Barcode scanner example project

Import both of these projects into Eclipse and you should be all set to go. Hopefully seeing the full projects will help people get up and running.

If this works for you and you don't already have Dropbox sign up for the free service via my referral link so I can have more space to host future example projects. Thanks!

Update: The easiest way to get this projects into Eclipse is to do the following. In Eclipse, go to the File menu, select the Import option, expand the Android folder, select Existing Android Code into Workspace. Then in the dialog that pops up select Finish. Now the project has been imported. If you have an error in your project, specifically with AndroidManifest.xml then you will want to right click on the project folder and select properties. Select Android and then choose the latest version of the Android SDK that you have installed. At this point the errors should go away, if they don't select the Project menu then Clean.

90 comments:

ayesha said...

Thank you Sir, It really help. But I had a problem with customized scanner plugin. BarcodeScanner works fine but if I need to make SCAN on button click or any other event. For that purpose I have made few changes in capture.xml and capture activity class. I have created new button name 'close' and created new function 'myFuction' that should be triggered on button click.

here is code of xml
http://pastie.org/4811161

here is code of java
http://pastie.org/4811161

which runs perfect, but guide me how to execute myFunction() on Button Click (on 'close' button Click event).

Simon MacDonald said...

@ayesha

Move line 174 to 169 and when you click the close button myFunction() will be called.

sangeeth_LVS said...

HI SIMON ,
i am sangeeth , when i try to upgrade my barcode Plugin to PHONEGAP2.0 using the LIbrary avilable in GITHUB. it is showing me an error like

Conversion to Dalvik format failed with error 1

do i need to use a seperate Library for Phonegap 2.0.i think there is a huge update made in cordova2.0 in the coding part . they have Removed IPlugin.java as far as i looked in to it GITHUB incubator of cordova class files .

java.lang.IllegalArgumentException: already added: Lcom/phonegap/api/IPlugin;

thanks in advance
Sangeeth

Simon MacDonald said...

@sangeeth_LVS

It looks like you are including cordova.jar twice in your build path. You don't need it in your library project libs directory, you only need it in your applications libs folder.

sangeeth_LVS said...

Thank You it helped me !!

sangeeth_LVS said...

Hi simon,
PHONEGAP QR encoder :
while Encoding the QRcode it is encoding and showing it in the new window . is it possible to store the Encoded QRcode in the PhoneStorage ? i think it is useful only in that way .

Thanks
Sangeeth Kumar V

Kim Stegenborg Madsen said...

Hi Simon

I´m trying to make this work but Eclipse complains about this line in BarcodeScanner.java:

getMenuInflater().inflate(R.menu.activity_barcode_scanner, menu);

"R cannot be resolved to a variable"

So i uncomment that line and then i can build, but get a new error from the APP it self "Scanning failed: Class not found"

Problem seems to be that in barcodescanner.js this:
BarcodeScanner.prototype.scan
should be
BarcodeScanner.scan

Now i don´t get the error but no scanner is startet up (i do have CAMERA and FLASHLIGHT permissions in AndroidManifest.xml)

What seems to be the problem?

Eclipse 3.7.2
Android: 4.0.3

Kind regards
Kim

Simon MacDonald said...

@sangeeth_LVS

That functionality is currently not implemented. It wouldn't be too hard to do but I don't have time to work on it right now.

Simon MacDonald said...

@Kim Stegenborg Madsen

I have no idea what is going on. In my two example projects the code:

getMenuInflater().inflate(R.menu.activity_barcode_scanner, menu);

is never used so I'm not sure about your starting point.

Also, BarcodeScanner.prototype.scan is correct in the JS. Based on that error you are seeing I'd guess you didn't add the correct lines into your manifest so it can find the capture activity. But again, I'm not sure of your starting point so it is hard to say.

Kim Stegenborg Madsen said...

Hi Simon

I´ve apparently used a different BarcodeScanner.java (from phonegap), which contains a bit more than yours:

public class BarcodeScanner extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

super.loadUrl("file:///android_asset/www/index.html");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.activity_barcode_scanner, menu);
return true;
}
}

So removing the onCreateOptionsMenu method got rid of the "R cannot be resolved to a variable"

However i still get the "class not found" error.

I´m gonna download your files once more and start from scratch again. Do i need anything besides these files? I mean, no additional phoneGap/Cordova etc.?

Kind regards
Kim

Simon MacDonald said...

@Kim Stegenborg Madsen

If you use the two projects I have linked to in my post you'll just need to import them into Eclipse. Nothing else is needed.

Kim Stegenborg Madsen said...

Okay, so i´ve downloaded the two projects again, importing them from scratch (library first).

The BarcodeLibrary has several errors in src (client.android, client.android.(book|encode|history|result) and many more)

The BarcodeScanner has 4 errors in the AndroidManifest:














So i don´t know, do i have a sick setup or is this expected?

After outcommenting the above i can build and get the Cordova icon and "device is ready", but i need to test the scanning function. I´m using the index.html file from your previous tutorial: http://simonmacdonald.blogspot.dk/2011/12/installing-barcode-plugin-for-phonegap.html

and then i get "class not found" again?

Kind regards
Kim

Simon MacDonald said...

@Kim Stegenborg Madsen

As you can see from the above, the error you posted did not get into Blogger. Don't post HTML as it can only handle very basic tags. Can you post the error up on gist or pastebin?

sangeeth_LVS said...

Simon

if u could give me a spark for saving the Encoded QR in to device storage . i think i could catch up and complete the Task . i was blank for 2 days trying this one .

Thanks
Sangeeth Kumar V

Simon MacDonald said...

@sangeeth_LVS

Sorry, I don't have time to go poking around the library project code. It shouldn't be too bad to save a view as a jpg though. You may wan to check out the screen shot plugin for example.

https://github.com/phonegap/phonegap-plugins/tree/master/Android/Screenshot

sangeeth_LVS said...

Simon,

When i try to share the QRcode Generated it is showing an alert box . "saying SD Card isnot Accessible ".

Kim Stegenborg Madsen said...

Hi Simon.
Here´s the AndroidManifest.xml in pastebin: http://pastebin.com/h0mqL8Af

Kind regards
Kim

Simon MacDonald said...

@sangeeth_LVS

Did you make sure to add the write external storage privilege to your android manifest.xml?

Simon MacDonald said...

@Kim Stegenborg Madsen

You need to go over the README again. You haven't added the bits to request the Camera & Flashlight nor have you added the necessary activities to call the scanner/encoder.

https://github.com/phonegap/phonegap-plugins/blob/master/Android/BarcodeScanner/README.md

Kim Stegenborg Madsen said...

Hi Simon

That´s why i earlier asked if i needed anything besides your two examples to import.

The camera section was there, the flashlight missing in your example has been added, and i´ve followed the README.md from start to end, but i still get the same error: "Class not found" when i press scan in the app.

I get some warnings from com.phonegap.plugins.barcodescanner/BarcodeScanner.java:

"The method success(PluginResult, String) from the type Plugin is deprecated" in method onActivityResult():
this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);


Tested on:
HTC Sensation: 4.0.3
Virtual device: 4.1.2
barcodescanner.js: 2.0
cordova: 2.1

The project is using Android 2.1, cout that be the problem?
Tell me what files do you need to see and i´ll pastebin them.

Kind regards
Kim

sangeeth_LVS said...

simon

why does all the Phonegap Application crashes on change in orientation . is there any fix for it .

thanks
sangeeth kumar

Kim Stegenborg Madsen said...

Hi Simon

FYI, i tried to use Android 4.0.3 against the phone with same Android sw, same result, class not found

Kind regards
Kim

Kim Stegenborg Madsen said...

More FYI

"Update (2012/08/09): As of PhoneGap 2.0 the plugins.xml file has been deprecated. It has been replaced with config.xml. So if you are starting a brand new project that has config.xml in the res/xml directory you will need to add your plugin declarations to this file. If you are using an older version of PhoneGap or upgrading an older project to PhoneGap 2.0 you can still use the plugins.xml file as we've got backwards compatibility (sort of). Please note though config.xml will take precedence over plugins.xml so you should not have both files in one of your projects as you'll end up tearing your hair out."

Exactly what i do :-) I did as the README told me to do, added the plugins.xml file from another project and added the barcodescanner line, but there was a bunch of other plugins aswell in that file, that might have conflicted with config.xml. Now i don´t get the class not found error anymore, but when pressing scan in the app it ask which program to execute the action (it´s in danish), and then dies when i select my app with this error:

threadid=1: thread exiting with uncaught exception (group=0x40aaf228)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.simonmacdonald.scan/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)

Any idea how to solve this?

Kind regards.
Kim

Simon MacDonald said...

@sangeeth_LVS

First off, not all PhoneGap applications crash on orientation change. That would make the framework pretty useless. If your app is crashing on orientation change you are probably missing the orientation attribute from your configChanges in the manifest.

Make sure you have the following line in your config:

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"

Follow the instructions at:

http://docs.phonegap.com/en/2.1.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android

Look at the end of point number 3.

Simon MacDonald said...

@Kim Stegenborg Madsen

Okay, it is pretty obvious that you aren't importing the example projects. If you did your manifest would be setup correctly. If you would like me to take a look at your setup please zip up your app and post it somewhere I can download it. I'll take a look at the setup and fix it for you. The back in forth of telling you every possible place to check will take too long. I'd rather fix it and tell you what was missing if that is okay with you.

Simon MacDonald said...

@Kim Stegenborg Madsen

Okay, it is pretty obvious that you aren't importing the example projects. If you did your manifest would be setup correctly. If you would like me to take a look at your setup please zip up your app and post it somewhere I can download it. I'll take a look at the setup and fix it for you. The back in forth of telling you every possible place to check will take too long. I'd rather fix it and tell you what was missing if that is okay with you.

Kim Stegenborg Madsen said...

Hi Simon.

I´m importing the example projects, it´s just not clear to me which way to do it (maybe cause it´s new to me to work in Eclipse, i´m a VIm man?):
Should i create a project and import them into that?
Should i import it directly (file-import), if so choose general->existing project into workspace or android->existing android code into workspace?
So i tried different approaches and probably messed up previous versions i guess. (how do i save a project in a safe place, so i don´t mess it up, trying new things? by copy project? or is there a smarter way to do it? For now i´m zipping the whole project in windows explorer once in a while...)

I´d like to figure out how it works and what i´ve done wrong

zipped file of the project is here:
http://home.emax.dk/files/BarcodeScanner.7z, this is the barcodescanner project - Do you need the library project aswell?

Kind regards
Kim

Kim Stegenborg Madsen said...

Hi Simon

Okay, i tried once more from scratch, this time i made it work, but not without certain challenges :-)

I Tried to import BarcodeLibraryProject and BarcodeScanner from scratch with file->import->General->Existing projects into workspace. Both says "no project found to import".

Imported them instead with file->import->Android->Existing Android code into workspace

BarcodeScanner:
"project.properties is out of sync with local file", wierd error... Editing the file with the eclipse text editor just showed a press F5 to reload, then it worked
100 errors (R cannot be resolved to a variable, and in AndroidManifest.xml "hardwareAccelerated", "XlargeScreens", "installLocation, 'configChanges' value 'orientation|keyboardHidden|keyboard|screenSize|locale').

I tried to debug that... Apparently "installLocation" was added in API level 8, but changing to api 8 or 16 doesn´t remove the error :-(

The Library was even worse, a bunch of errors in the /src dir, i couldn´t get rid of.

So i put it aside, looked at it an hour later and decided to make copies of both projects to "filename"+"01". Suddenly the errors on the Library dissapeared. Any idea why this happend?

Adding the library didn´t work for the BarcodeScanner01 project, but adding library01 did. Then all i did was to follow the https://github.com/phonegap/phonegap-plugins/blob/master/Android/BarcodeScanner/README.md - I changed the bit about adding to res/xml/plugins.xml, instead i added it to res/xml/config.xml since i use phonegap2.0 (add that to the guide?)

other than that, i replaced your index.html with the one you´ve written here: http://simonmacdonald.blogspot.dk/2011/12/installing-barcode-plugin-for-phonegap.html (maybe add that to your example as with-barcode-js.index.html?)

Thanks for your help and patience.
Kind regards.
Kim

Cebbz said...

Hello Simon,

sorry for my english, because i'm french.

I want to create a custom barcode scanner with phonegap. I have read a lot of tutorial on internet to integrate the barcode scanner plugin in my project, but this plugin never work...(always this error : Class not found)

I'm not a specialist on java or eclipse environement...

Maybe you can send me a full code source work perfect for help me for this project...

I hope you can help me for that.

please please please.

my email adress is sebastien.capron(at)gmail.com

Thank for all.

Sébastien.

Simon MacDonald said...

@Kim Stegenborg Madsen

I'm glad it is finally working for you. Yes, when you import these examples they should be done as Android projects. One other thing I need to change is after you import you should change it so it is built with the latest version of Android. That would make a lot of those errors go away.

Kim Stegenborg Madsen said...

Hi again.

I triede to import it at home to (Linux), still got the errors in AndroidManifest.xml, so how did i get rid of those? Added a space somewhere in the file, so it´s changed compared to your version, then saved it and then... errors is gone.

So wierd, but i thought I´ll share this so the next person who experience this doesn´t spend countless hours figuring out what Eclipse is complaining about...

Kind regards
Kim Stegenborg Madsen

Simon MacDonald said...

@Cebbz

The full source code for both the library and example project are available at the links in my post. Do this to get the projects in your workspace:

File -> Import -> Android -> Existing Android Code into Workspace

vincuo said...

Hi Simon.

Sorry, i'm sure missing some important point.

I'm trying to run that application.

When i launch the application I have only the "Device Ready" window of PhoneGap.

But how i launch a scan ?

I'm afraid that the "Example project" is like the "Hello World" of PhoneGap.

Thanks for a reply.

Simon MacDonald said...

@vincuo

It wasn't you it was me. The project got clobbered on Dropbox somehow. I just put the correct version back so download it again.

mistik1 said...

I have to ask, Does this plugin even support the cordova 2.2.0 or android sdk 4.x?

For two days now I have tried with both your sample projects and my own and I cannot get this to compile.

Simon MacDonald said...

@mistik1

Yeah, it works on my phone running Android 4.1 without any issues. What is your compile issue?

Unknown said...

Hi!

Found this great plugin last week and have been trying to get it work for me. I get it to scan and it kind of works. After scanning it peeps and says "Product Found" but does not show this UPC code. How can I get this code to some variable for example? I would need it to be in url like http://address.com/page.php?id=HERE

How can I achieve this? I have used your example projects. Thanks!

Simon MacDonald said...

@Thomas Berg

The success callback should be invoked with the UPC in result.text. Possibly you need the updated plugin that I just pushed for version 2.2.0.

Unknown said...


I'm still getting a ton of errors. Since this is my first time with Eclipse, I'm guessing it's something fundamental (e.g. Ant? Working directory?). Is it apparent what's missing by looking at this screenshot of my Eclipse session.

http://postimage.org/image/nmpy32du9/full/

Simon MacDonald said...

@roy whitburg rwhitburg

Well it is hard to tell but the first thing you need to do is to switch what API level you are building CaptureActivity with. Right click on the project folder, select Properties, Android and select the highest level API version you have. The problem is you are building with an API level that doesn't support xlargescreens.

After that I'd try closing an opening the project as it seems like your gen folder is not getting updated. That is where all the R errors come from.

Unknown said...


Thanks for responding. I have the latest API level checked (17) in both the library and application.

I right clicked and "closed project" then "opened project" for both as well, which did make some of the red alerts go away in the navigator view. But I'm still having the same problems (see image).

Most of the problems refer to a CaptureActivity Path. I noticed that I have no such physical directory. Was that supposed to have been (automatically or manually) created at some point?

http://postimage.org/image/s1h7o27w3/full/

Unknown said...

I'm using the latest API. Closing and opening the project did get rid of some of the problems, but most remain, as you can see below. Not sure where else to turn, as this is my first phonegap project.

http://postimage.org/image/s1h7o27w3/full/

Thanks.

Unknown said...

Disregard my previous posts. I "Cleaned" it and, other than a bunch of warnings, it's working well now.

Thanks for the app!

Unknown said...

hello mrs. Mac donald, i try used your app, but barcode scanner doesn`t show me a alert, why?

Simon MacDonald said...

@ALMORA DEV

Didn't give me much to go on. What do you see in "adb logcat"?

Unknown said...

this is my log

D/CordovaLog(31978): *********** start scan *********
D/CordovaLog(31978): file:///android_asset/www/js/index.js: Line 39 : *********** start scan *********
I/Web Console(31978): *********** start scan ********* at file:///android_asset/www/js/index.js:39
D/CordovaLog(31978): *********** finish scan *********
D/CordovaLog(31978): file:///android_asset/www/js/index.js: Line 50 : *********** termina funcion scan *********
I/Web Console(31978): *********** finish ********* at file:///android_asset/www/js/index.js:50
D/DroidGap(31978): Paused the application!
D/CordovaWebView(31978): Handle the pause
D/OpenGLRenderer(31978): Flushing caches (mode 0)
D/OpenGLRenderer(31978): Flushing caches (mode 1)
D/DroidGap(31978): onDestroy()
D/CordovaWebView(31978): >>> loadUrlNow()
W/IInputConnectionWrapper(31978): showStatusIcon on inactive InputConnection
D/DroidGap(31978): DroidGap.onCreate()
D/CordovaWebView(31978): Origin to allow: http://127.0.0.1*
D/CordovaWebView(31978): Origin to allow: .*
I/CordovaLog(31978): Found log level DEBUG
I/CordovaLog(31978): Changing log level to DEBUG(3)
I/CordovaLog(31978): Found preference for useBrowserHistory=false
D/CordovaLog(31978): Found preference for useBrowserHistory=false
I/CordovaLog(31978): Found preference for exit-on-suspend=false
D/CordovaLog(31978): Found preference for exit-on-suspend=false
D/JsMessageQueue(31978): Set native->JS mode to 2
D/DroidGap(31978): DroidGap.init()
D/CordovaWebView(31978): >>> loadUrl(file:///android_asset/www/index.html)
D/PluginManager(31978): init()
D/CordovaWebView(31978): >>> loadUrlNow()
D/DroidGap(31978): Resuming the App
D/SoftKeyboardDetect(31978): Ignore this event
W/webcore(31978): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
W/webcore(31978): at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1691)
W/webcore(31978): at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
W/webcore(31978): at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1803)
W/webcore(31978): at android.webkit.WebView.sendOurVisibleRect(WebView.java:2924)
W/webcore(31978): at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
W/webcore(31978): at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
W/webcore(31978): at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
W/webcore(31978): at android.os.Handler.handleCallback(Handler.java:605)
W/webcore(31978): at android.os.Handler.dispatchMessage(Handler.java:92)
W/webcore(31978): at android.os.Looper.loop(Looper.java:137)
W/webcore(31978): at android.app.ActivityThread.main(ActivityThread.java:4441)
W/webcore(31978): at java.lang.reflect.Method.invokeNative(Native Method)
W/webcore(31978): at java.lang.reflect.Method.invoke(Method.java:511)
W/webcore(31978): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
W/webcore(31978): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
W/webcore(31978): at dalvik.system.NativeStart.main(Native Method)
D/SoftKeyboardDetect(31978): Ignore this event
D/DroidGap(31978): onMessage(onPageStarted,file:///android_asset/www/index.html)
D/Cordova(31978): onPageFinished(file:///android_asset/www/index.html)
D/DroidGap(31978): onMessage(onNativeReady,null)
D/DroidGap(31978): onMessage(onPageFinished,file:///android_asset/www/index.html)
D/DroidGap(31978): onMessage(networkconnection,wifi)
D/DroidGap(31978): onMessage(spinner,stop)
D/DroidGap(31978): onMessage(spinner,stop)
D/DroidGap(31978): Paused the application!
D/CordovaWebView(31978): Handle the pause
D/OpenGLRenderer(31978): Flushing caches (mode 0)
W/IInputConnectionWrapper(31978): showStatusIcon on inactive InputConnection

thanks and regard

Simon MacDonald said...

@ALMORA DEV

What are your configChanges set to in the manifest.xml? Put it up on gist or pastebin.

Unknown said...

sorry, thanks in advance, you are helping me a lot

Simon MacDonald said...

@ALMORA DEV

I rejected your last comment as you can't post xml in blogger it doesn't show up. Put it up on gist or pastebin like I said.

Unknown said...

sorry for the delay. This is the two manifiest.

http://pastebin.com/hjjnhzje

the config

http://pastebin.com/6yKf7WMe

thanks.

Simon MacDonald said...

@ALMORA DEV

Nothing is jumping out at me here.

Unknown said...

Hi Simon,

For the past 3 months we don't have the problem on barcode scan, but just today. When I click the button scan on our app which is installed in Nexus 7 (android 4.2). It shows
"Sorry,the Android camera encountered a problem.You may need to restart the device."

Simon MacDonald said...

@Jeoffrey Galbizo

Have you tried the latest version of the plugin? A lot of folks have had problems with the barcode scanner and the Nexus 7 but I don't have one to test.

Unknown said...

opps sorry for late reply.
i figured it out by installing the zxing barcode scanner app, it won't work the scanner if you scan on front camera. nexus 7 has no camera on back.

thanks.

Anonymous said...

hey simon, the library is perfectly working in emulator and few devices, but in few device like samsung GT-1900 the app is being hanged after the scan, and nothing can be done except force exit :(. please help me with this asap!

Simon MacDonald said...

@Shiva Acharjee

What are you seeing in "adb logcat" when you hang the app?

SAVIOUR said...

Hi @simon,
I imported your com.simonmacdonald.scan.BarcodeScanner prject to my work space and i got
[2013-04-11 18:27:10 - com.simonmacdonald.scan.BarcodeScanner] Unable to resolve target 'android-16' as error can you please help me. Thank u in advance

Simon MacDonald said...

@SAVIOUR

Start your Android SDK Manager and download API level 16.

sapna rai said...

Hi, Simon
your Barcode_scanner project working fine on my android device(2.3),but it is not scanning any barcode.
i m just find a rectangular view to scan barcode but it is not working.
plz reply asap.

Simon MacDonald said...

@sapna rai

Some older devices had pretty bad cameras that can't possibly focus on the barcode. What are you seeing in "adb logcat"?

sapna rai said...

@Simon MacDonald : thanks for reply..actually it is not scanning any barcode.On focussing the rectangular view over any barcode, I don't get any result and any message..Do I need to write some additional codes?...Do help me..

SAVIOUR said...

Hi Simon;I got error in com.simonmacdonald.scan.BarcodeScanner android manifest
""

error: Error: No resource found that matches the given name (at 'label' with value '@string/
share_name').

Simon MacDonald said...

@sapna rai

See previous reply.

Simon MacDonald said...

@SAVIOUR

It sounds like you haven't added the library project to your project.

Unknown said...

Hi Simon,


How can I redirect to another html page after scanning a QR?

Right now it is just showing "Found URL" and redirect itself back to the main index.html.

Which part of code I should look into?

I'm using the LibraryProject vers 2.2.0 and your current example project from this post, with updated barcodescanner.js and BarcodeScanner.java from 2.2.0.


Thanks in advance!

Karen

Simon MacDonald said...

@Karen Wong

In the success callback for the scan you can take the url returned and open the web page.

Unknown said...

Sir, your barcode scanner is absolutely perfectly working, we've used the app for almost a year but today, I compile eclipse project with the latest version cordova 2.7.0. All of a sudden BarcodeScanner.java got an error "cordova cannot resolved or is not a field" and "Plugin cannot be resolve to a type". I configured build path, search google but still got the error.

Simon MacDonald said...

@Jeoffrey Galbizo

The Plugin class was deprecated in favour of CordovaPlugin. You'll need to update your BarcodeScanner plugin to the 2.2 version.

https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner/2.2.0

Chris Martinez said...

Hi Simon, I hope you can help me. I just started using PhoneGap and have installed the latest Phonegap version and BarcodeScanner, I can get the app running, but it crashes as soon as it recognizes the bar code with the following error:

java.lang.RuntimeException: Unable to resume activity {com.csmcommunication.MediaLib/com.csmcommunication.MediaLib.MediaLib}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=195543262, result=-1, data=Intent { act=com.phonegap.plugins.barcodescanner.SCAN flg=0x80000 (has extras) }} to activity {com.csmcommunication.MediaLib/com.csmcommunication.MediaLib.MediaLib}: java.lang.NullPointerException. I tried downloading your sample projects, but am looking through the code and everything seems to the same. Any thoughts? Please let me know if you need me to send anything.. Thanks in advance for your help.
- Chris

Chris Martinez said...

Hi Simon, Um. Yeah, you must be magic - I got it working. Thanks! - Chris

Unknown said...

Hey Simon. Looks like a great project!

I am struggling with one problem though: When I am exporting the whole thing to Android apk I get this error :"conversation to dalvik format failed with error 1".
I checked your recent solution for this error and that's not working for me(I don't have jar conflict). Also checked if there any conflicting class and couldn't figure it out. any ideas?

Unknown said...

Is there any chance you could let us know how to set the barcode scanner up in Android Studio im struggling to figure out how to import the project thanks

Simon MacDonald said...

@Lee Doel

Sorry I haven't had the chance to upgrade them for Android Studio.

Simon MacDonald said...

@Yonatan Wolowelsky

Without seeing your project I can only point to the most likely cause which would be two jars that include the same classes.

Jeff said...

Hi Simon -

I've imported both zip files into Eclipse and I can do a Run As to my tablet, but I get "Unfortunately, BarcodeScanner has stopped." I don't know what to do next.

Thanks,
Jeff

Simon MacDonald said...

@Jeff

What do you see in "adb logcat"?

Unknown said...

Hi Simon,

I have imported second zip file into Eclipse and when I run it on my phone or emulator, But I get "Unfortunately,I get Barcode Scanner stopped".

Logcat error message shows " Class NOT FOUND EXCEPTION" unable to instantiate the activity.

Simon MacDonald said...

@Shraddha Pandey

What class is missing? Did you remember to add the library project to your app in the properties->android section of Eclipse?

Unknown said...

sir , i am new to phone gap and hybrid applications,i have implemented this natively,now i want to this in a hybrid way, so i download and imported this code to eclipse but i am getting error in manifest file as :


Description Resource Path Location Type
error: Error: No resource found that matches the given name (at 'label' with value '@string/share_name'). AndroidManifest.xml /com.simonmacdonald.scan.BarcodeScanner line 74 Android AAPT Problem

xyz said...

Demo app seems doesn't build with API 18. I must use API 16?

xyz said...

Tried on a real device I got this:

08-30 18:01:14.329: D/dalvikvm(7082): Late-enabling CheckJNI
08-30 18:01:15.639: E/Trace(7082): error opening trace file: No such file or directory (2)
08-30 18:01:15.699: V/ActivityThread(7082): com.simonmacdonald.scan white listed for hwui
08-30 18:01:16.109: W/dalvikvm(7082): Unable to resolve superclass of Lcom/simonmacdonald/scan/BarcodeScanner; (534)
08-30 18:01:16.109: W/dalvikvm(7082): Link of class 'Lcom/simonmacdonald/scan/BarcodeScanner;' failed
08-30 18:01:16.109: D/AndroidRuntime(7082): Shutting down VM
08-30 18:01:16.109: W/dalvikvm(7082): threadid=1: thread exiting with uncaught exception (group=0x40b43930)
08-30 18:01:16.229: E/AndroidRuntime(7082): FATAL EXCEPTION: main
08-30 18:01:16.229: E/AndroidRuntime(7082): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.simonmacdonald.scan/com.simonmacdonald.scan.BarcodeScanner}: java.lang.ClassNotFoundException: Didn't find class "com.simonmacdonald.scan.BarcodeScanner" on path: /data/app/com.simonmacdonald.scan-1.apk
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2224)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.app.ActivityThread.access$600(ActivityThread.java:153)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.os.Looper.loop(Looper.java:137)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.app.ActivityThread.main(ActivityThread.java:5260)
08-30 18:01:16.229: E/AndroidRuntime(7082): at java.lang.reflect.Method.invokeNative(Native Method)
08-30 18:01:16.229: E/AndroidRuntime(7082): at java.lang.reflect.Method.invoke(Method.java:511)
08-30 18:01:16.229: E/AndroidRuntime(7082): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-30 18:01:16.229: E/AndroidRuntime(7082): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-30 18:01:16.229: E/AndroidRuntime(7082): at dalvik.system.NativeStart.main(Native Method)
08-30 18:01:16.229: E/AndroidRuntime(7082): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.simonmacdonald.scan.BarcodeScanner" on path: /data/app/com.simonmacdonald.scan-1.apk
08-30 18:01:16.229: E/AndroidRuntime(7082): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
08-30 18:01:16.229: E/AndroidRuntime(7082): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-30 18:01:16.229: E/AndroidRuntime(7082): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
08-30 18:01:16.229: E/AndroidRuntime(7082): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
08-30 18:01:16.229: E/AndroidRuntime(7082): ... 11 more
08-30 18:01:20.279: I/Process(7082): Sending signal. PID: 7082 SIG: 9

What's wrong?

Thanks.

Simon MacDonald said...

@nutella

I built against sdk 18 and ran it on my Nexus 4 running Androd 4.3 (sdk 18) without any problems.

Simon MacDonald said...

@omkar kulkarni

Right click on the project, select properties, select Android then look down the bottom at the Library section. It is either missing the library project or has the wrong name.

Yoann Estepa said...

Hey Simon! Great blog! It sure has been useful for me since I started working with phonegap.

Is there any chance you could help me using the BarcodeScanner Plugin? I installed it and the scan seems to work fine (camera launching and QRCode detected). But when I try to obtain the result using the classic success function, it's empty and the result code is return_cancelled.

I am using phonegap 3.0. Would you have any idea to where I should look?

Thanks in advance,

Yoann

Simon MacDonald said...

@Yoann Estepa

What do you see in "adb logcat"?

Unknown said...

I tried the barcode scanner example but the LogCat shows a reference error in index.html:

file:///android_asset/www/index.html: Line 31: Uncaught Reference error: app is not defined

Thanks, Jos

Simon MacDonald said...

@Jos Hendriks

Something has gone wrong before this point as it does not appear that the linked in JS files got loaded. That should be the only way app is not setup.

Unknown said...

hi simon,
thanks for this best tutorial and other examples.

well i have android phone with both kind of camera (front and back) n

now i want to use only front camera to scan QR code using barcode scanner but its not working, it alwasys uses back camera.

can you plz, give me some advice ?

Thanks buddy

Simon MacDonald said...

@Jayesh Vadgama

You'd have to dig into the ZXing library code in order to enable front camera support.

Muthu karunarathna said...

Thank you so much..it was big help for my project..keep it up your great works..!!!