Integrate zxing barcode scanner into your Android app natively using Eclipse

June 13, 2011

Update: Please note that this tutorial was written over a year ago. ZXing has moved on quite a bit since then as have the Android Developer Tools. I haven’t had time to revisit and update the post but it should give you a good steer in the right direction. Some of the comments at the bottom may be able to help you out if you encounter any troubles.

Edit: Sean Owen, one of the developers for ZXing has posted a comment to this blog warning of the pitfalls of integrating ZXing into your own app; doing so just to avoid having your users take that extra step of installing from the market is not a good reason. I completely agree with this. There are many advantages to using the intent based approach as outlined in his comments. My motivation is for an enterprise app that does not have access to the Android market and involves my client installing zxing manually on thousands of devices before they are able to distribute to its business customers.

So to be clear, do not use this method unless it is absolutely necessary, and if you do have to – make sure that override your intent filters so that other apps that want to use zxing do not end up calling your modified version. Also, if zxing is already installed, then you should use that by default instead of your modified version.

ZXing is one of the most popular barcode scanning applications on the market. They make it very easy for you to integrate into your application via an intent but this means that your users must manually install the application from the market.

Fortunately, the app is also open source so I will show you how to cleanly build this capability into your project.

Please note that the awesome developers of this product have released the src under the Apache v2.o license so please be sure to adhere to the terms of this license and give them full credit for their work. http://www.apache.org/licenses/LICENSE-2.0

Step One: Obtain the zxing src code
The src can be found at http://code.google.com/p/zxing/source/browse/trunk. Specifically you only need the android/ and the core/ projects. Use svn to checkout these to your local hard-drive.

Step Two: Build zxing core using Apache Ant
You will need to build the core project into a jar file using apache ant (download from here http://ant.apache.org/ivy/download.cgi). Using a shell or cmd prompt navigate to the root directory of the downloaded zxing src and execute “ant -f core/build.xml”. This will produce a file core/core.jar which we will use in the next step.

Step Three: Build ZXing Android using Eclipse
Create a New Android Project (File –> New –> Android Project).
Set the project name to ZXing (or similar).
Select the “Create project from existing source” radio button
Click “Browse” and navigate to the android project that you downloaded from zxing and click “OK”
Select “Finish”

The project will not currently build. We need to add the core.jar file (that we produced in the previous step) into our project. Right-click on ZXing project –> properties –> Java Build Path –> Add External Jars –> Navigate to and select core.jar –> Open –> OK.

Actually, while we’re here we should do one more very important thing! Right-click on ZXing project –> properties –> Android –> Scroll down and check/tick the “Is Library” checkbox –> OK.

Step 4: Include ZXing Android into your project.
Within Eclipse,  Right-click on YOURPROJECTNAMEHERE project –> properties –>Android –> Scroll down to Libraries section –> Click Add –> Select ZXing (which should appear as an option as a result of completing previous step).

Next, in some trigger function e.g. button press within your code you should add:

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);

In the same activity you’ll need the following to retrieve the results:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   if (requestCode == 0) {
      if (resultCode == RESULT_OK) {
         String contents = intent.getStringExtra("SCAN_RESULT");
         String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
         // Handle successful scan
      } else if (resultCode == RESULT_CANCELED) {
         // Handle cancel
      }
   }
}

Almost there! One of the current limitations of Android Library projects is that it will not pull anything from AndroidManifest.xml into your project.
So if we try to invoke the above code we will receive a runtime exception because your Android app has no idea how to handle the scan intent.
To fix this you just need to copy the following into your AndroidManifest.xml:

<activity android:name="com.google.zxing.client.android.CaptureActivity"
   android:screenOrientation="landscape"
   android:configChanges="orientation|keyboardHidden"
   android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
   android:windowSoftInputMode="stateAlwaysHidden">
   <intent-filter>
      <action android:name="android.intent.action.MAIN"/>
      <category android:name="android.intent.category.DEFAULT"/>
   </intent-filter>
   <intent-filter>
      <action android:name="com.google.zxing.client.android.SCAN"/>
      <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

And as Columbo would say, “Just one more thing!”. Add this permission to the top of your AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA"/>

EDIT: You need to do yet one more thing! You need to add the core.jar (produced in Step two) to your new project (Right-click your project –> Properties –> Java Build Path –> Add External JARS… –> Select core.jar –> OK). Thanks to Marco and Markosys in the comments for spotting and pointing out the omission!

About these ads

328 Responses to “Integrate zxing barcode scanner into your Android app natively using Eclipse”

  1. Lorenz Stierlin Says:

    Thanks for this post. It was really helpfull. But i have the problem that the retangle with the red laser line is in the right corner and not in the middle of the screen… i use a android 2.2 htc desire HD for testing. curiously on a virtual device it works correctly. maybe you can help me? thanks a alot

  2. Oskar NRK Says:

    Hi! I tried the integration and it works, thanks :)

    But there’s a problem: “Barcode Scanner” takes control of application name: the application name displayed is “Barcode Scanner”, not the one I provided in my application manifest, I can’t fix it. Any suggestion?


    • Doesn’t the barcode scanner go full screen without titlebar?
      In any case, if you want to customise, you can go into the src of the Android ZXing app, change stuff there and recompile. I did this to disable many of the menus.

      • Oskar NRK Says:

        Yes it does. The problem that I launch Barcode Scanner with a button in my application but including ZXing as library the main app I’m developing gets “Barcode Scanner” as application name. It seems like Barcode Scanner overrides my manifest settings.
        Now I try to edit Barcode Scanner manifest a bit. Thanks :)

      • Oskar NRK Says:

        Found the problem: the “values-” folders. I’m Italian and my test device language is Italian.

        By default the main app’s app_name overrides the library’s app_name but using locales and not in the main app doesn’t work. I deleted all the “values-” folders in the library and now all works fine.

        Now I’m trying to disable menu in the capture view.

    • Carlos Says:

      Good question men… You help me a lot!!! Thanks Oskar

  3. Drew Says:

    Hi, I am an absolute noob here. But someone help me out here?

    On Step 4, it says I am suppose “Select Zxing” in the library. But when I click on “Add”, there is no option at all, not to mentioned Zxing. Did I do anything wrong? Please help!

    Thanks!
    Andrew

    Thanks!

  4. G.Letellier Says:

    Thank’s for your tutorial !! Works Great !!!

  5. emna Says:

    hi! help me please, i did all the three first steps but on step 4 there is no options, what should i do?

  6. Kevin Says:

    emna, I believe Step 4 is worded incorrectly

    The original:

    Step 4: Include ZXing Android into your project.
    Within Eclipse, Right-click on ZXing project –> properties –>Android –> Scroll down to Libraries section –> Click Add –> Select ZXing (which should appear as an option as a result of completing previous step).

    Should read:

    Step 4: Include ZXing Android into your project.
    Within Eclipse, Right-click on YOURPROJECTNAMEHERE project –> properties –>Android –> Scroll down to Libraries section –> Click Add –> Select ZXing (which should appear as an option as a result of completing previous step).

    If you followed the original wording you would be adding library project to itself–which is senseless. Other than that, pretty nicely done… thanks for the help.

  7. Darshan Says:

    HI !

    Please check this application on github called QRC

    https://github.com/egure/diordna/tree/master/QRC

    This has the integrated QRC source , you can build application based on this.

    Thanks,
    Darshan

  8. emna Says:

    another question please! when i push the button to start scanning i only got the retangle with the red laser line without a result, i waited… but still nothing. what could be the problem please!


    • The scan mode in the post is set to QR code. With this setting it will only scan 2d barcodes


      • I have the same problem. I installed the Zxing app (that is being built from the downloaded source codes) into my device. I get the rectangle with the red line, but it just keeps on trying to read the barcode. No matter if it is a 1D or 2D barcode.
        Although the Zxing app that is available in android market works perfectly.
        Could the android target platform be an issue? I have tried android 2.2 and 2.1 to build this project.
        Great tutorial btw.

      • Sayali Says:

        I have same issue. Does it have other modes? What are they & how to use them. Can you please provide any tutorial link if any?

    • Jarek Says:

      What idiot must the creators of the lib be to enforce QR mode. What the hell for?

  9. Brandon Says:

    First off this is a brilliant article. I have been searching over the net for help with fully integrating the zxing and was able to solve my issues through this.

    Now to my wonderful new hurdle:
    How to get the product details with the successful scan. I have been looking through the zxing source code and have been trying to impelement the ProductResultHandler ( http://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/result/ProductResultHandler.java ) without success in getting the product info. Any assistance would be greatly appreciated.

  10. Marco Says:

    great tutorial.
    I’m going to link it on my blog, I hope you could be happy about that ;)


  11. [...] zxing barcode scanner in your Android application Hi there, let me highlight this good tutorial of Damian Flannery about adding barcode scanner capabilities to your Android [...]

  12. Aditya Says:

    Hi,I have copied and paste in android manifest file…but still getting
    run time exception…Please help…

    Thanks,
    Aditya…

  13. Manish Says:

    thanks a lot..this code works wonders..!!!

  14. Ted Says:

    Thx for this tutorial, but everytime I build the android Project from existing source (step 3), src and res are full of unresolved variables. Can anyone help?


  15. Hi all, I have a problem. I did everything as in tutorial, but still have a problem. I think ZXing project witch I convert to library can’t correctly included to my project. First time when I add ZXing library to my project I see green icon, I ‘ve built project, run on emulator and got “runtime exception”. After I go to properties an see red icon on Properties -> Android -> Library (earlier included)…
    Maybe someone can help me ?

    This is screenshot of my error – http://imageshack.us/f/19/unledqpk.png/

  16. Aditya Says:

    Hi,
    I have follwoed step by step.But getting Run time Error.My manifest is like below….

    Please Help…..want urgently.

  17. Aditya Says:

    Hi,
    I have follwoed step by step.But getting Run time Error.My manifest is like below….

    Please Help…..want urgently.

  18. Jacob Says:

    When I add ZXing as a library I get like 400 errors.
    Lots of things which cannot be resolved to a type like AddressBookParsedResult BarcodeFormat. Hope someone can point me to what im doing wrong.

  19. david Says:

    Great article, thanks!

    I’m having a little trouble following, though. So I have the whole zxing project, and I’ve been able to build the core.jar using ant.

    In Eclipse, when I create the new project, it wants to default to android 2.3.1. I want it to use 2.2, since my phone doesn’t have 2.3 yet and I’d like to try this out on it. I can import the core.jar and have it build with 2.3.1, but if I try to change the project to 2.2, I get an error in my manifest with it not liking the xLargeScreens attribute, then all kinds of other errors pop up and it all goes to hell.

    Is it because the core is built for 2.3.1 as well? How do I make that build for 2.2?

    Also – if I create my own project and try to add in my CaptureActivity project (using 2.3.1 – just trying to see if i can get a full build going), it adds the CaptureActivity_src and then I get all these errors unless I also add core.jar to my project.

    I’m doing this on a mac with eclipse 3.6 and all the up to date android stuff.

    Thanks!

  20. Quang Anh Says:

    Thank you so much,this tutor help me a lot .

  21. r4ul90 Says:

    I’m trying to follow your tutorial. Currently I can add the ZXing project as a library to another project, when I make it the first time I see a tick icon under the reference column, but after I close this window and check properties again I see a red X, I don’t understand what can be wrong, perhaps Eclipse? I’m using Eclipse 3.6.2 and I can build the app but when I try to actually scan it crashes I believe it has something to do with this reference, I would appreciate any help you can provide me with, thanks in advance and great tutorial.

  22. r4ul90 Says:

    Are you using Linux or Mac? I can’t find a way to make this work finally I solved the red X issue, now I always see a green tick the reason was that the projects were located in different partitions.

    Now the problem I have is the ‘library project’ I’ve added the core.jar file (I’ve built it lots of times always getting a success message), but somehow it doesn’t work I get errors (tons of them) in the source files, I suppose those errors should disappear when the file (core.jar) is added to the project, but for me it doesn’t work (it’s frustrating) I’ve already added it many times as an external jar.

    Hope you can help me I’m using Win 7 x64 and Eclipse 3.7.0. Thanks in advance for your help.

    • r4ul90 Says:

      I solved the issue I set the library project profile to android 2.2 and that made it work. Of course the core.jar file was added as an external jar.

      • Rahul Popuri Says:

        Hi,
        I tried what you said, and it makes the compiling errors in the library go away, but when I launch the activity it gives me a message: “Sorry the Android camera encountered a problem. You may need to restart the device.”

  23. Alejandro Says:

    I followed all the steps and finally I can use the Barcode Scanner with my application but just if the Barcode Scanner is installed or if I used the debbuger of Eclipse (which installs the Barcode Scanner App from the library created on the step 3). My question is: How can I fully integrate the Barcode Scanner code into my application without install it and with no trace of the original Barcode Scanner? I think is weird for the user that my app installs another app in the device, and I’m not sure if I’m doing something wrong.
    Thanks.

  24. Marco Says:

    Amazing tutorial, works perfectly!

    I have only one question, if I press the “CAMERA SCAN” button my phone (that has Barcode Scanner APP installed) asks me:
    “complete action using”
    - BARCODE SCANNER
    - MY APP

    Is there a way to specify in the intent not to show the “complete action” dialog? and just start MY APP as default?

    thanks :)


    • Thanks.

      You need to change the action intent (in the zxing that’s included in your app) to something custom.

      e.g. Change public static final String ACTION = “com.google.zxing.client.android.SCAN”; to String ACTION = “com.yourco.yourproject.android.SCAN”; in com.google.zxing.client.android.Intents.java (in ZXing project)
      and change to in the AndroidManifest for the ZXing project.

      Then Recompile. That should do it.

      • Marco Says:

        Thank you works great :)

      • Tom Says:

        Would you be able to post what your two manifests look like for this? I cannot for the life of me get this to work. I keep getting

        android.content.ActivityNotFoundException: No Activity found to handle Intent { act=net.blueearth.clowns.android.SCAN (has extras) }

        Thanks!

  25. JayaVenkat Says:

    Hi,
    Actually I followed this tutorial line by line but integrated zxing to my own project but when button clicked the scanning is not performed please correct my problem

  26. Venkat Says:

    Hi,
    Thanks for providing this tutorial, I have followed this tutorial line by line everything works fine .But while integrating with my app I found problem. Scanning is not done when button is clicked

  27. ajay Says:

    I tried to import this project. After successfully creating core.jar and loading the android project – i get tons of errors related to strings.xml.
    Use %s as a placeholder for the product ID, and %f for format

    I get

    error: Multiple substitutions specified in non-positional format; did you mean to add the formatted=”false” attribute? strings.xml /qrcodeprj/res/values line 96 Android AAPT Problem

    • Aditi Says:

      I received a similar error too. Downloaded fresh copy of the android project from zxing project and the errors were resolved.

  28. RacZo Says:

    Hey guys!

    I did everything (get the source, compile with Ant, get the core.jar to my project and include the zxing project as an Android Library on my App) and… sweet! Got the scanner to work (even without asking me what App to use) and after scanning, it returns to my App.

    BUT… it gets back to my own Activity and I try to get the results on the onActivityResult method, resultCode is always RESULT_CANCELED and the intent is null, so no results! :(

    I call the CaptureActivity (on my manifest) with:

    Intent intent = new Intent(“com.myapp.SCAN”);
    intent.setPackage(“com.myapp”);
    intent.putExtra(“SCAN_MODE”, “PRODUCT_MODE”);
    intent.putExtra(“SCAN_WIDTH”, 800);
    intent.putExtra(“SCAN_HEIGHT”, 200);
    startActivityForResult(intent, 0);

    In my Manifest I added the CaptureActivity like this:

    This is how I’m trying to read the results:

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    Log.d(LOG_TAG, “onActivityResult was reached!”);
    if (requestCode == 0) {
    if (resultCode == RESULT_OK) {
    // Successful scan
    Log.d(LOG_TAG, “Barcode Scanner successful.”); } else if (resultCode == RESULT_CANCELED) {
    // Handle cancel
    Log.d(LOG_TAG, “Barcode Scanner canceled.”);
    }
    }
    }

    I’ll appreciate a lot if you give me some light about this guys!

    Thanks in advance!

  29. Marco Says:

    I all, it works perfectly thanks!
    I also had to add the core.jar to my project (not just to the ZXing project). Hope this will save some time to somebody!

    Thanks again :)

  30. jaav Says:

    Hi Damian,
    This is a great post, it helped me a lot in getting a scanning app up and running.
    Thank you.
    Grtz

  31. Markosys Says:

    Many thanks for pulling this together. It’s a great jumpstart into integrating the scanning activity into my app.

    I also needed to add the core.jar (see @marco) to my new project to eliminate errors resulting from adding my Zxing project library. Does this mean that something in my build process or path could be incorrect?

    For those attempting to run on 2.2SDK / API 8:

    Building on Android SDK 2.2 / API 8 required modification of the AndroidManifest.xml file, removing:
    ‘android:xlargeScreens=”true” ‘ from .

    The issue was discussed on the Zxing project site (read to the bottom): http://code.google.com/p/zxing/issues/detail?id=864.

    Thanks,
    Mark

  32. Markosys Says:

    Regarding comment from markosys:
    ‘android:xlargeScreens=”true” ‘ from .
    should read
    ‘android:xlargeScreens=”true” ‘ from .

    regrets for the typo/omission.

  33. Ajeet Says:

    I did everything (get the source, compile with Ant, get the core.jar to my project and include the zxing project as an Android Library on my App) Got the scanner to work (even without asking me what App to use) and after scanning, it returns to my App…Help needed ..whats going wrong ..can you tell me.

  34. AndroidDev Says:

    I did everything as you have shown, when I call the barcode intent, the scanning screen appears but instead of the camera screen it appears white background in the scanning box(which has a red line), but it scans the barcode when i point my phone to a code.

  35. J.d. Ballard Says:

    Sorry, but this is not “Native”, this is using intents. Natively would be using the core directly in your code.


    • Well if you followed the article then you just compiled the src and linked it to your project; so you can either hook into your own view or call the scan function via an intent.
      The term native in this context is used to illustrate that you don’t need to install the barcode scanning app separately.

  36. David Says:

    It still requires the barcode app, isnt there a way to fully integrate the code without having to rely on the user to install the Barcode scanner app?


    • Um, it doesn’t require you to install the app separately. That’s the whole point. You must be doing something wrong.

      • David Says:

        That is very strange, there are two “errors” I get, one just loops me back when I press the button, it sends me back to the classical layout, and sometimes it crashes because apparently “No activity found to handle intent”, and when I install the scanner it suddenly works. Do you have a .zip maybe of the project? I really dont know what Ive been doing wrong..I followed the tutorial to the letter (also tried bringing in the source into the project but I still get that “no activity found to handle intent”.

        thanks

  37. Shane Says:

    Thank you so much for this awesome post! I have searched for hours for the answers. After reading through your post, I realize that I was only hitting pieces of steps previously, but now the whole picture makes sense. Thanks again!

  38. V Says:

    Great article!
    Thanks from Mexico!

    For those having problems…remember that, when you create your Android project, you must specify a platform version – according to this version some AndroidManifest.xml tags will change. So, until you fix your AndroidManifest.xml you will see a lot of errors about the R class.

  39. bidu Says:

    Hey Damian nice tutorial, but i guess i have a problem i follow everything that you order nevertheless i have a problem in the last step that says: “EDIT: You need to do yet one more thing! You need to add the core.jar (produced in Step two) to your new project (Right-click your project –> Properties –> Java Build Path –> Add JARS… –> Select core.jar –> OK). Thanks to Marco and Markosys in the comments for spotting and pointing out the omission! ”

    but i cant find a way to find the core what i just see are the projects, and the project that i import the core.jar dont have this file to select.

    Here is a printscreen maybe this help you to understand what im trying to say ;)

    http://img703.imageshack.us/img703/7075/errorpus.png

    Sorry for poor english but im brazillian and my english isnt too good.

  40. kshitij vyas Says:

    Hi…thnx up till now…but m stuck in different kind of problem…actually m following all the steps..But when i build Core folder and look into it firstl i didnot find core.java.then is run command again.this time there was core.java but there is no manifest file.So,eclipe is not allowing to built project without manifest.But should i do?

  41. kshitij vyas Says:

    m sorry for the poor english.It was actually core.jar..not core.java.

  42. Sean Owen Says:

    Hi all, I’m one of the developers of Barcode Scanner. This is no doubt helpful, and the spirit is in the right place.

    However I must say we discourage people from copying-and-pasting Barcode Scanner in this way. You’re encouraging people to create apps that make people think they’re using our app, when they’re not.

    I gets worse when people do this, then modify the code in ways that break it. Guess who gets the e-mail for support? We also see plenty of people just do this to add ads or affiliate links.

    The motivation seems to just be “because I don’t want to make people install someone else’s app”, which is a flimsy reason. It may increase profits for the app maker, but to the extent it does, it subtracts a little from the open-source community. It also harms the user experience IMHO; the user is not getting fixes and improvements of the real Barcode Scanner app this way. Finally, you can see how much programmer time it’s wasting to try to get the integration working, when Intents takes 5 minutes.

    I won’t suggest you should remove this post of course; I would request that you consider the downsides of this approach, the negative externalities on the project, and perhaps emphasize that in the text.


    • Thanks for your comment Sean, I completely agree with everything you outlined. I’ve updated the text at the top of the article; hopefully to your satisfaction. I’d like to leave the article up because I think it has saved people a lot of time. However, if you feel it’s being overwhelmingly used for the wrong reasons and is harming the open-source project then I’ll take it down because that’s the last thing I want to do.

      Best regards,
      Damian

      • Sean Owen Says:

        Thanks Damian, that’s a great reply. Let’s leave it there. I’d rather people have all the info they could want, and also all the issues to consider, and this helps that goal. Thanks.

      • Iulia Ion Says:

        Then why not have the BarcodeScanner app installed by default on your phone, with the Android OS distribution? If it is not used by other apps, and it is not there by default, I do not see a reason why we should ask users to install “yet another app”. This is really poor user experience, and it will just make people walk away from such apps.

      • Sean Owen Says:

        Why not have it baked into Android itself? Well, I’m afraid I’m not that decision-maker! What do you mean? (As it happens — this was developed at Google and was almost a part of Android 1.0, but wasn’t, and probably should not be. But, this could easily be an app that’s nothing to do with Google.)

        It *is* used by other apps. It is preinstalled on some phones, but not most. Again — hardly something the app controls.

        I don’t think it’s such a big deal to install another app. I don’t argue with people who think it’s a bad experience. I’ve open sourced all this code to help you build it into your app. I’m merely emphasizing the “you build” and “your app” — I’m speaking out against pure copy-and-paste jobs out there which have little added value.

        Sure, it’s easier for them. Sure integrating makes the “experience better”. It may make them more money. These are still no justification for directly ripping off someone’s work.

      • Iulia Ion Says:

        Sean, I understand your point, am very grateful for very good library you implemented and by no means do I want to rip it off. I am, however, going to say that to the non-technical user it makes a great difference if he is asked to install another app or not. Apart from that, there are other reasons why I need to integrate the ZXing library directly in my app. I want to use ZXing to transfer sensitive bits of data, such as public/private keys, which I really do not want to leave my app (especially not to an app that has Internet permissions and can be updated remotely). Also, for the sake of good user experience, I would like to change the screen that displays the QR code to give the user customized instructions, instead of displaying the content of the barcode (which is all a big junk of gibberish that makes no sense to the user).

        That being said, one think I am totally missing out on by basically ripping your code apart, is the great updates you will be releasing to improve the performance of the decoder. For this purpose, do you think you could release a distribution that would be easy to incorporate in an app (for example a jar file with the library for Android).

        Thank you very much. I really appreciate your work and your help.

        Best,
        Iulia


    • Hi Sean!

      Indeed, your words are very true.

      I have just convinced my boss to let users download Zxing, Barcode Scanner; and through the Android Intent Integrator, the whole picture looks much more stable and trustful.

      I hope other CEO’s are able to be convinced.
      :)

    • Richard Says:

      Hi Sean, thanks for the great code but I found this page when trying to find how to integrate zxing with my app. You have said that using Intents takes 5 minutes to integrate but I can’t find a clear explanation of how to do this.
      It would be helpful to me (and I’m sure others) if you could provide a link to the ‘right’ way to integrate using intents.
      Thank you

    • Neil Says:

      Hi Sean,

      I appreciate your input here. I’ve decided that it is a better idea to allow the user to manage updating of the zxing code through the market so that we as developers of other apps don’t have to mess with that. However this is still the only tutorial that I have found on the web that actually shows how to launch the scan activity using intent in the EclipseDE.

      My main issue here is that I’ve looked through the IntentIntegrator and would like to use it in my code but I can’t seem to find any resource out there using the keywords that I have in my vocabulary to actually figure out how to import the IntentIntegrator in my Activity in order to utilize it without adding zxing as a library in Eclipse.

      Any guidance would be greatly appreciated.

      Thank you,
      -Neil


      • Just copy the IntentIntegrator and IntentResult source files into your project and you should be good to go.

      • Sean Says:

        The simplest thing is to just copy the source code. Or, build a jar from the project by typing ‘ant’ in android-integration and add that as a library jar. Couldn’t be easier.


  43. [...] /android project as a library in your own project. Damian Flannery has put together a very nice step-by-step blog post for doing [...]

  44. Iulia Ion Says:

    Thank you very much for the explanation on how to get this done. This was very useful. Especially since the process is so counter-intuitive. One thing I totally disagree with you on: It is a really BIG deal asking users to install another application just so that they can install yours. People are lazy, things are too complicated, and they cannot spend their time installing apps, so easily integrating the barcode scanner into your app, is totally worth it.


  45. Hey Damian,

    I actually set up the same project structure independently of your post and I’m seeing an odd issue when I install my application on my phone. I end up getting two icons, one launches my app and the other launches the original barcode scanner. Have you ever seen anything like that in your experience?

    Thanks…

    Simon

    • Sean Owen Says:

      It means you haven’t taken out our CaptureActivity from your copy of the manifest. You should probably start with your own manifest. If you copy ours (aside from issues here) you’re going to get settings and such that don’t apply to you.

  46. Anthony B Says:

    Hmm well I seem to have got it working… but for some reason the mask outside of the border is red rather than just a transparent black (making it look like half of the screen is just red). Any idea why this might be happening? Thanks.

  47. Bob Says:

    Thanks for the great instructions. However, I am having an issue using ZXing as a library. Every time I attach it in Eclipse it looks fine (little green tick). However, when I then check that it is still included, it has changed to a red cross and the Project name is simply listed as a question mark.

    I have tried many different API levels, rebuilding etc, but nothing seems to work.

    Any suggestions about how to fix this would be much appreciated.

    • Bob Says:

      I managed to get past this problem by deleting the minimum SDK levels listed in the ZXing manifest.

      Now I get a fatal error running it which states:
      android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN (has extras) }

      I can remove this by separately installing Barcode Scanner, but as soon as I uninstall it, the error returns. Obviously it isn’t actually loading the ZXing or Core jar…. even though both are listed properly under ‘Library Projects’ and ‘Referenced Libraries’.

      Any ideas would be welcome because this is driving me nuts now! Thanks.

      • Jakob Says:

        Had the same problem. My problem was in my manifest. Where I forgot to put the inside the tags
        From there, it worked like a charm.

        Else ensure that you have copied it, excatly as in the post.

        Try renameing it to your own:
        something.someting.android.SCAN (in Activity)
        and similar in the Manifest
        and in the class Intents.java in ZXing project


      • Jakob, I’m having this problem as well. Can you explain your comment about forgetting to put something inside the tags?

      • akramiahmad Says:

        Hi there..
        Jakob can you please explain your comment, I am desperate for the solution

  48. monta Says:

    hi this is wonderful ,
    but i want to impliment in my application a sample scan code bar.
    that is to say, win i want i scan a code a bar, it will store in imageview (same application fidme)
    please can you help me.

  49. Jakob Says:

    Everything works! Except I have problems when I access the menu in Barcode Scanner. Menu shows, but when I select a menu item (Help) I get:

    java.lang.NoSuchFieldError: com.google.zxing.client.android.R$id.help_contents

    I also have problems when clicking on preferences (but found a work-around for that)

    Help

  50. Prashant wankhede Says:

    I have problem with creating the core.jar ,plase he;p me.thank in advance

  51. coderealm Says:

    Dear damian flannery,
    Please help me with the basics. I installed ant. My zxing is in c:\zxing. When I open command prompt on windows 7,
    I type in:

    >C:\zxing
    >’C:\zxing is not recognized as internal or external command,operable program or batch file.

    So I don’t even get past the second step. can you please help me with the command line statements


  52. i am facing an error java.lang.VerifyError in while starting CaptureActivity

  53. sdcool Says:

    I’ll try this out. Thanks a lot for this valuable write up.
    I have 2 queries:
    1. Do I have to write the camera code for Zxing to be used? Or will it automatically invoke the camera functionality?
    2. If I want the scanned result to be from my sqlite db how can I achieve it?


  54. Can you please give the core.jar, I couldn’t able to make it .. Thnaks


  55. Note that ADT v.14 no longer allows resource fields (R. etc.) to be constants in library projects. This means they can’t be used in case statements. So once you clean up the manifest (xlargeScreen item noted above) you will have to go through and find the 3-4 case statements (highlighted by errors) and convert them. The fix suggestion in the gutter of the code indicated how to use Eclipse’s QuickFix feature to auto-convert these Switch statements to if-else.

  56. Satyaseshu Says:

    Hi, Thanks for nice tutorial. I implemented this Zxing code scanner in my application. everything working fine. but i got extra icons i.e, 3 icons in left top, right top and bottom right. what’s these icons? is there any help and i would like keep my own button i.e., close button. if i clicked on close button the current activity will close and goes to previous activity. can any one tell how to achieve this problem?? this is my mail is s.seshu143attherategmaildotcom..
    Thanks in advance………………

  57. Justin Says:

    I’ve modified the ZXing source code to make encoding/decoding a bit easier. The project is located at:
    http://code.google.com/p/android-quick-response-code/

    The new source allows direct integration of encoding and decoding without having to install ZXing or use Intents.

  58. quangho Says:

    i do step by step but it do not work, an excception was found in logcat: unable to start com.google.zxing.client.android.CaptureActivity
    please hepl me !!!

  59. Asep rohimat Says:

    Hi all, i tried with this procedure and always get error. finally i found tutorial with call zxing via intent with barcode scanner app must install in phone. i can call barcode intent but my phone always get error after scan the barcode, what procedure or what kind off setup must i do. this is my code :

    public class zxing_act extends Activity {
    /** Called when the activity is first created. */
    private EditText edittext1, editText2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    EditText edittext1 = (EditText) findViewById(R.id.edittext1);
    EditText editText2 = (EditText) findViewById(R.id.editText2);

    Button next = (Button) findViewById(R.id.button1);
    next.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    Intent intent = new Intent(“com.google.zxing.client.android.SCAN”);
    intent.putExtra(“SCAN_MODE”, “QR_CODE_MODE”);
    startActivityForResult(intent, 0);
    }

    });

    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
    if (resultCode == RESULT_OK) {
    String contents = intent.getStringExtra(“SCAN_RESULT”);
    edittext1.setText(contents);
    String format = intent.getStringExtra(“SCAN_RESULT_FORMAT”);
    editText2.setText(format);

    } else if (resultCode == RESULT_CANCELED) {
    // Handle cancel
    }
    }
    }

    sory my english is very poor.

  60. syed Says:

    Can some one upload the core.jar file pls.

  61. preethan Says:

    very useful , covered evry detail thanku

  62. preethan Says:

    One important point , the core file has to be added to library of the new project as well.

  63. crv Says:

    I am able to launch ZXing App from my native App,thats fine,when I launch,it is able to scan but not Showing any details of it like Url,name or address..Plz suggest me with some solutions

  64. maliks Says:

    please some one help me out via this … i tried each and every thing to make my app run but it shows lot’s of error’s … someone plz help me out … plz drop email at sudhirmalik2011@gmail.com if you can solve my prob … i need to scan qr code with my app only

  65. Tony John... Says:

    Thanks a lot Damian, it really helped.. had to jump through a few hoops.. one thing I would like to mention is that.. the ZXing project and the project that includes it as a library should be in the same drive and accessible via logical path ..

    Sean Owen.. I understand your argument but one of the challenges I see while making an application is that users would frown on the need to install another application to make a main application work.. for people who have a scanner installed well and good.. but others would not freely go ahead and install it. I sure do understand the cost component and also understand the work that you and your team have put it.. it would be awesome if there was some standard way to integrate ZXing directly without having BarcodeScanner installed as an application which would help you and also adhere to the means you expected the product to be used..

    FYI I am not a Android JAVA guru.. I understand and have worked in many programming languages and starting to wade into the Android Space..

  66. Jakob Says:

    I have a major problem when using the integration on 3.0 and 3.1 (But not 3.2)
    In 3.0 and 3.1 the search rectangle is moved to the lover left corner and scanning is really bad! I found out that the barcode still gets recognized if it is in the center of the viewfinderview. (But the user experience is really bad)

    Have any one else experienced this problem? Help!

  67. Nikhil Says:

    HI All,

    I followed all the steps as mentioned but I am getting the following exception at run time

    01-11 11:21:48.411: E/AndroidRuntime(18807): FATAL EXCEPTION: main
    01-11 11:21:48.411: E/AndroidRuntime(18807): java.lang.ExceptionInInitializerError
    01-11 11:21:48.411: E/AndroidRuntime(18807): at java.lang.Class.newInstanceImpl(Native Method)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at java.lang.Class.newInstance(Class.java:1429)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.os.Handler.dispatchMessage(Handler.java:99)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.os.Looper.loop(Looper.java:123)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at android.app.ActivityThread.main(ActivityThread.java:4627)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at java.lang.reflect.Method.invokeNative(Native Method)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at java.lang.reflect.Method.invoke(Method.java:521)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    01-11 11:21:48.411: E/AndroidRuntime(18807): at dalvik.system.NativeStart.main(Native Method)
    01-11 11:21:48.411: E/AndroidRuntime(18807): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
    01-11 11:21:48.411: E/AndroidRuntime(18807): at com.google.zxing.client.android.CaptureActivity.(CaptureActivity.java:106)
    01-11 11:21:48.411: E/AndroidRuntime(18807): … 15 more

    Can any please help me I am really new to this and android as well..

    Nikhil

  68. Cady Says:

    I am having issues with these steps. I cannot even get past step 2. what file do I actually download? There are three options…how do I install it?

  69. ghouse Says:

    hi thanks for the post i have one doubt what if want to use this library in my app i have to pay money for them

  70. Ali Says:

    I am novice here please help me, I have done all steps and code compiles well but when I press a button to start the SCAN activity nothing happens, my current activity just reloads (showing me the same button). the code defines intent and starts activity but
    it never goes to “onActivityResult” method. Does anyone have a solution for this?


  71. [...] I completely agree with this. There are many advantages to using the intent based approach as outlined in his comments. My motivation is for an enterprise app that does not have access to the Android market and involves my client installing zxing manually on thousands of devices before they are able to distribute to its business customers. Integrate zxing barcode scanner into your Android app natively using Eclipse « Damian Flannery's Bl… [...]

  72. lindo Says:

    If you want to achieve TRUE NATIVE integration of zxing (i.e. not using Intents) then you need only import the core.jar file as a Library into your project and then start using it. To cover a LOT of ground faster you can bring the ZXing App’s code (i.e. zxing/android/src/) but you will need to copy some of the resources from ZXing App’s res/ to your own project’s /res. Then you can go about cutting out the crap you don’t need such as, in my case: Book reader, Menus, History Manager, Google Shopping, Intent handling, most of the *ResultHandlers (AddressBook, Email, Geo, ISBN, Calendar, SMS, Tel, Wifi, perhaps more). And then go on to customise where you need.

    • Sean Owen Says:

      Please don’t encourage people to copy android/. We have enough problems with total copy and paste jobs already. This is officially quite discouraged.

      • lindo Says:

        Is it not well written code? Is it not open-sourced under the Apache License 2.0? Would you have me do something else with the code, other than use it as a baseline to enhance, to somehow fulfil my needs? I don’t understand your angle on this, other than the potential to profit via sales of your paid App (which is unreasonable, given the code is open-sourced). Talk about subtracting from the open-source community ;)

      • Sean Owen Says:

        This has been covered many times. How would Firefox devs feel if you pasted their code into your app and called it “LindoBrowser”? Not illegal, but does not seem ethical.

        I’m sure you’re one of the good guys, and not one of the many people out there who publish clones on Market, so that they can add their brand name, or add money-making ads and affiliate links, or worse. That’s really what I’m speaking out about.

        I do think it subtracts from the community when you tell people to not use the existing app, and instead copy and paste the code so that you don’t drive any users to the existing app. That’s what you are helping people do here, but I think reasonable people can disagree about whether that’s so bad. To be sure, a lot of people are doing this from companies who want to copy and paste into their app to increase their own profits.

        I’d also ask you to ask yourself who you think gets the support e-mail when something that looks a load like Barcode Scanner, but isn’t, has an error? Again: coming out of the community’s “pocket”, which is mostly mine.

        If you are encouraging innovation based on this code, I’m all for that. But I doubt that starts with copying all the code. I’d sure like to see someone build substantially their own, better app.

        I can’t understand your point about profit. I don’t sell an SDK. Maybe you don’t know that I am the primary developer? I have given four years of time to the open source project, for free. App revenue pays for even more work on the project now, but I still ‘lose money’. Have a look at what I put in here: http://code.google.com/p/zxing/source/list

        If I wanted more money, I’d do contract work or something and not spend any more time on the project. Now, what exactly have you given to the people here?

  73. lindo Says:

    I guess, like you, I’ve provided a solution of sorts and now I’m here, like you, rambling on :)

    You make gross misjudments about what I’ve done, what I’m doing, and why I’m doing it. Understandable, since you don’t know. But it’d be a shame if you act this way towards everyone that seeks to utilise the core natively.

    If I can provide some constructive feedback that may alleviate the need to base off /android/ App’s code: the project lacks documentation and examples (apart from the /android/ App) as to how to utilise the core at all, let alone best practices. Hence why I ended up at this thread, only to find its just using the Intent method (the method described in this thread is more ‘bundled’ than ‘native’).

    Bait: Is Indian Giving “ethical”? Is complaining about not making a profit from your contribution to open-source work a very strange thing to do?

    Your time and effort is appreciated, at least, by me.

    • Sean Owen Says:

      I don’t know what you’re doing and don’t judge it. I bet you are a force for good. I just said I don’t want to encourage people to go this road; this advice can be used for good, but judging from questions on StackOverflow and the mailing list, 80+% of people just want a quick, free solution for their own company, and don’t want to give back or have any connection to the open source project. So most consumers of this advice are just being helped to do something I don’t support, so I think it’s OK to say I don’t want it supported.

      android/ is not an API or library and so is not documented to be used like that. That is why there aren’t “examples”. It’s not meant to be obtuse, and I think it’s clean and reasonably documented. More docs are welcome.

      Where I am complaining about not profiting? I was just defending against the implication that I am motivated by money now, by pointing out that I hardly profit.

      We were paid handsomely by Google for the initial work. After Google, I continued to support it gratis, with what little time I could sparse. The paid app is an effort to justify sparing a bit more time, since there is much that could be done; improvements are back-ported regularly, not kept to myself. (Really: I was interested to see how a paid app / open source commercialization works on a small scale.)

      Listen if you want to get indignant about somebody here, I’d point you to Big In Japan / ShopSavvy. It’s a lovely app and service. But they sell an “SDK” which is mostly zxing inside. They modified the scanner to send back parts of everything you scan to their servers. They track your location and are most certainly out for profit. They had to be told several times to get the open source licensing right. They have never contributed anything to the project. The most ‘thanks’ the project got were bizarre legal threats (http://osdir.com/ml/zxing/2010-10/msg00196.html) which didn’t stop until Google legal got involved.

      Really. I am not the guy you want to come after.

      • lindo Says:

        Don’t worry, your code is in good hands (in this case!).

        Really stinks what Big In japan / ShopSavvy did, vultures :/ All the more reason to outdo them via open-source, eh?

  74. Piotr Says:

    Friends… what could be wrong when I get errors like this

    Description Resource Path Location Type
    The method call() of type KillerCallable must override a superclass method KillerCallable.java /ZXing/src/com/google/zxing/client/android/result/supplement line 38 Java Problem
    ?

  75. Sri Says:

    I have followed the exact steps and I get a lot of errors but they all have the same concept which is R cannot be resolved to a variable.

    How could I fix this, any help would be appreciated

    Thanks in Advance

  76. Vyacheslav Says:

    thanks man! You’ve just saved my life!

  77. Alex Says:

    Please, I trying and don’t have errors, but the app doesn’t works, it just stay the same, can someone, please send me a example project sucessfull working ? A simple project with a button calling the zxing, PLEASE !!!!

    Thanks

    • malik Says:

      i have done all the above things and made my own project but when i run my app on phone and scans the QR code it only says “Found URL” and does not redirects me to that URL and takes me back to same page to scan qr code again and again same happens, how can i solve this problem ?

  78. Conor Caslin Says:

    Thanks for posting this. It was really helpful. But I’m having a problem when the QR Scanner screen with the red laser line is launched. The scanner appears in the right corner and not in the middle of the screen.any help is appreciated. thanks in advance

  79. kamil Says:

    Hii i was getting error wen i created apk file and tried to install that can u give me code where have successfully done….
    can u just upload ur that project for me
    Thanks in advance..

  80. dada Says:

    hi i have a doubt if i want to display the qrcode image in the same layout where i have entered the string then how can i achieve that one any suggestions will be great help

  81. Disya Says:

    Thanks.. man it worked for me :D

  82. dwking Says:

    Can’t build the zxing successfullly… somebody tip me off..
    When I add the import i get the error “manifest file missing” … should be pretty easy to fix..but… :(
    help..please.

  83. Veptune Says:

    I got an exception when i start the intent, it is strange because i step correcly your tutorial, i checked again and again :

    02-26 19:29:30.409: E/Surface(8982): Surface (identity=50) requestBuffer(0, 0, 0, 0, 00000033) returned a buffer with a null handle
    02-26 19:29:30.409: E/Surface(8982): getBufferLocked(0, 0, 0, 0, 00000033) failed (Out of memory)
    02-26 19:29:30.409: E/Surface(8982): dequeueBuffer failed (Out of memory)
    02-26 19:29:30.409: E/ViewRoot(8982): OutOfResourcesException locking surface
    02-26 19:29:30.409: E/ViewRoot(8982): android.view.Surface$OutOfResourcesException
    02-26 19:29:30.409: E/ViewRoot(8982): at android.view.Surface.lockCanvasNative(Native Method)
    02-26 19:29:30.409: E/ViewRoot(8982): at android.view.Surface.lockCanvas(Surface.java:314)
    02-26 19:29:30.409: E/ViewRoot(8982): at android.view.ViewRoot.draw(ViewRoot.java:1536)
    02-26 19:29:30.409: E/ViewRoot(8982): at android.view.ViewRoot.performTraversals(ViewRoot.java:1323)
    02-26 19:29:30.409: E/ViewRoot(8982): at android.view.ViewRoot.handleMessage(ViewRoot.java:1961)
    02-26 19:29:30.409: E/ViewRoot(8982): at android.os.Handler.dispatchMessage(Handler.java:99)
    02-26 19:29:30.409: E/ViewRoot(8982): at android.os.Looper.loop(Looper.java:143)
    02-26 19:29:30.409: E/ViewRoot(8982): at android.app.ActivityThread.main(ActivityThread.java:4293)
    02-26 19:29:30.409: E/ViewRoot(8982): at java.lang.reflect.Method.invokeNative(Native Method)
    02-26 19:29:30.409: E/ViewRoot(8982): at java.lang.reflect.Method.invoke(Method.java:507)
    02-26 19:29:30.409: E/ViewRoot(8982): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    02-26 19:29:30.409: E/ViewRoot(8982): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    02-26 19:29:30.409: E/ViewRoot(8982): at dalvik.system.NativeStart.main(Native Method)

  84. Veptune Says:

    I add some details :

    If i install zxing app, and if i select it instead of my app when i got the dialog box, , it is working.

    And if on eclipse, on the zxing library, i uncheck the checkbox “is librairy” and i run the project, it works too.

    The library has been corrected imported to my project, as i got no compile error. Any idea ? strange

    thanks

  85. Veptune Says:

    OK, i tink i got it, it was because on the activity section, i change to put my own activity instead of keep android:name=”com.google.zxing.client.android.CaptureActivity”

    But now, i m getting another exception :

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.project/com.google.zxing.client.android.CaptureActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class com.mycompany.project.CustomCameraView

    What is very strange is that CustomCameraView is another class (which extends surface view) but which is not called on my activity, it has nothing to do with the acitivity which will start the intent.

    Any idea ?

  86. Veptune Says:

    OK, i found, the problem was actually really in my CustomSurfaceView class. Why i get this error when i start the intent as this class is not needed ? why i did not get the error before ? mystery

    thanks for this tutorial anyway :)

  87. Rhood Says:

    Hello,

    I followed this steps, but this doesn’t work.
    My error: Under my project in Java Build Path in Libraries is error that testlib.jar – C:\…\android\bin (missing)

    Could someone help me?

    Thanks a lot.

  88. sochinda Says:

    Hi,

    It really works, but I get the result is always null, please tell me how can I do?


  89. [...] Sean Owen, one of the developers for ZXing has posted a comment to this blog warning of the pitfalls of integrating ZXing into your own app; doing so just to [...]

  90. galaxias Says:

    Hi, with some changes all is ok now! Thank you!!
    Good tutorial!

  91. Rhood Says:

    Hello,

    I want to scan QR code with BarcodeScaner if is it install, otherwise, i want to scan code with BarcodeScanner library.
    But when i lunch my app, it give me a chiose witch scanner i want to use.
    Is it possible to implement this? How?

    Thank you in advance.

    • dwking Says:

      have you read through the post?

      • Rhood Says:

        Yes i had.
        sorry, that I didn’t write more information what I want to do.
        I implemented that my app read qr code. But when I install BarcodeScaner, that app give me a question witch codeScanner i want to use.
        Can i implement both this version with Intents, or some other ways?
        Maybe is this a stupid question, but I am new in android.
        Thank you

  92. jpopes Says:

    Thank you very for the very detailed article about nothing.
    Every single step of this is wrong, or severely incomplete.

    You should remove this from the internet.


    • The zxing project has changed quite a bit since I took the time to write this last June. Still, this post has helped quite a few people and gives you a good head-start if you’re working with the latest zxing release.

  93. Nobody Says:

    The resultCode for me is always RESULT_CANCELED. Somebody else mentioned this above but there was no solution posted? Any ideas?

  94. laura Says:

    Hi, I am following all the steps and I have a problem launching the scanner view.
    When it starts, I can’t see the camera view, instead of this I see a grey screen with a white rectangle inside, but I can’t see what I want to scan.

    If I launch the scanner in my main activity it works fine, but when I launch it from another activity I have this problem.

    Do you know what is happened?

    Thanks in advance

    PD: I hope I explained well because my English is not very good

  95. fivos Says:

    Hello everybody,

    I have followed the 4 steps many times very carefully, but in the third step ..

    “Create a New Android Project (File –> New –> Android Project).
    Set the project name to ZXing (or similar).
    Select the “Create project from existing source” radio button
    Click “Browse” and navigate to the android project that you downloaded from zxing and click “OK”
    Select “Finish” ”

    after doing that, there is an “x” on the project’s name (ZXing) on the Package Explorer of Eclipse. If i click on the project, to see it’s contents, i see that there is also an “x” on the src file.

    What could be wrong?

    Thank you in advance!

  96. Vandan Says:

    Sir.
    While Doing Step 3,I got Following Error in Console

    “com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Unable to read E:\Android\Android\android-sdk\AndroidManifest.xml: java.io.FileNotFoundException: E:\Android\Android\android-sdk\AndroidManifest.xml (The system cannot find the file specified)”

    Can You Help Mee To Remove this Error.. It Really Urgent Sir..
    Thankyou

  97. sam Says:

    Hello Sir
    i has problem to Download Zxing Src .plz tell me How it is Downloaded.
    thanks And Regrads
    plz reply

  98. Colin Mills Says:

    Hi, I went through the tutorial and it all went without a hitch but when I try start the activity I get :

    FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to resume activity {fish.tracer.project/com.google.zxing.client.android.CaptureActivity}: java.lang.NullPointerException
    ….
    Caused by: java.lang.NullPointerException
    at com.google.zxing.client.android.CaptureActivity.onResume(CaptureActivity.java:183)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150) etc…

    This is the line causing the nullpointerexception :
    viewfinderView.setCameraManager(cameraManager);

    Why is it calling onResume() for this activity, shouldn’t it be onCreate().

    If someone has any idea as to whats causing this error, advice would be greatly appreciated.
    Cheers,
    Colin.


    • Did you declare the android.permission.CAMERA in your manifest?

    • Vito Andolini Says:

      Hi, I had the same problem (same error, same line of code) and was able to fix it. Here’s what happened:

      Although this didn’t happen right away, a few compile errors popped up in my library project for the Android source. The errors were related to the fact that the zxing source code was using R.id.somevalue values in switch statements. This isn’t allowed anymore. The fix was to change the switch statements to if/else statements. I did this, and the errors went away.

      Once I retested the app, I no longer got the NPE went away. My only guess is the compile errors prevented the R file from being created correctly (or at all), so at runtime when the findViewById method is passed R.id.viewfinder_view, that id doesn’t exist, and thus is null

      Hope that helps.

      • Egilson Cabral Says:

        wow, i had this error and spent a long time to solved it, thanks Vito for the help, finally i could solve it, fixing many classes in Zxing project, that are using switch statements with R.id.something. I just wanted to know why the Zxing org didnt fix it yet?! anyway, its working to me now!
        thanxs again!


  99. [...] Hace un tiempo, me planteé como integrar Zxing barcode scanner en un proyecto propio para no tener que llegar a tener instalado ninguna aplicación extra (a pesar de la posibilidad que ofrecen los propios desarrolladores del proyecto para utilizar intents, y de que uno de sus creadores nos advierte de las desventajas de usar esta posibilidad) [...]


  100. [...] For some time, I’ve been considering how to integrate Zxing barcode scanner in a project without having installed an extra app to use it (although they give you the chance to use an intent to test if Barcode Scanner is installed and use it). One of ZXing’s creators gave us some reasons of why not to do this, and if you want you can read them here [...]

  101. Eduard Gimenez Says:

    Hi,

    I’ve tryed to integrate ZXing into my application, for security reasons, apparently when ZXing is wrapped into my app it takes a lot more time to recognice QR Code. Does it make any sense? Thanks

    Eduard

  102. Alex Wong Says:

    Hi,

    I have recently facing some problems after finishing step4.

    public class MobilePOSActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }
    Intent intent = new Intent(“com.google.zxing.client.android.SCAN”);
    intent.putExtra(“SCAN_MODE”,”QR_CODE_MODE”);

    }

    I tried to add intent.putExtra to the code, but it’s indicating that (“mismatched construct”).And I checked the src file, it seems there are no “/.SCAN” file inside. Would you please help?

    Thanks,
    Alex

  103. Mohamed Rafiq Says:

    Hi ,

    I am facing this error and have been stuck for days with it. Would be grateful if some one can help me solve this. I have done exactly as mentioned in the blog.

    03-23 23:54:09.141: E/AndroidRuntime(1574): FATAL EXCEPTION: main
    03-23 23:54:09.141: E/AndroidRuntime(1574): java.lang.ExceptionInInitializerError
    03-23 23:54:09.141: E/AndroidRuntime(1574): at java.lang.Class.newInstanceImpl(Native Method)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at java.lang.Class.newInstance(Class.java:1409)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.os.Handler.dispatchMessage(Handler.java:99)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.os.Looper.loop(Looper.java:130)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at android.app.ActivityThread.main(ActivityThread.java:3701)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at java.lang.reflect.Method.invokeNative(Native Method)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at java.lang.reflect.Method.invoke(Method.java:507)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
    03-23 23:54:09.141: E/AndroidRuntime(1574): at dalvik.system.NativeStart.main(Native Method)
    03-23 23:54:09.141: E/AndroidRuntime(1574): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
    03-23 23:54:09.141: E/AndroidRuntime(1574): at com.google.zxing.client.android.CaptureActivity.(CaptureActivity.java:107)
    03-23 23:54:09.141: E/AndroidRuntime(1574): … 15 more

    • Chellappa K N Says:

      After all the comments, i finally see the last comment as the same problem as MINE.
      I got the same issue, instead of adding Core.jar, i directly copied the core source code into zxing project.

      There could be some issue with the Ant command which we use to make core.jar.
      Apart from this , i am also facing another issue.
      Now, when CaptureActivity class is called, it calls HelpActivity .
      During this , i am getting an “Unable to find an explicit activity class”.
      It is trying to look for the activity in the main Project;s AndroidManifest.xml file.
      The Help Activity is already in zxing project created as part of the instructions above.
      So i am stuck here.
      If the author or someone else replies to my problem, it wud be gr8..
      Thanks,
      Chellappa

      • Chellappa K N Says:

        In addition to the above comment, i just added the HelpActivity in the main Project’s AndroidManifest.xml file.
        I think this is not the right approach.
        But it worked now.
        I will wait for someone to comment on this..

        Thanks,
        Chellappa

      • bintang Says:

        hey how do you add that core source code to zxing project?


  104. Hi great tutorial…I was trying to integrate it but it app crashes with java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
    then i realised will this work on emulator..i dont have a phone to test..How can i fake the camera to take pictures..is this cause of app crash???

  105. Pallavi Says:

    hello,i have integrated zxing library into my application and i have tried executing the above snippet,but iam getting “the application has stopped unexpectedly” on emulator.Please help me to fix this.

  106. Pallavi Says:

    hello,i have integrated zxing library into my application and i have tried executing the above snippet,but iam getting “the application has stopped unexpectedly” on emulator.Please help me to fix this.

  107. Pallavi Says:

    Hello,I have integrated zxing library in to my application,i have tried executing the above QR code,iam getting-”the application has stopped unexpectedly” on emulator.Please help me to fix this and iam awaiting for your reply…………………………

  108. Nagarjuna Says:

    Hello
    when i use
    Intent intent = new Intent(“com.google.zxing.client.android.SCAN”);
    intent.putExtra(“SCAN_MODE”, “PRODUCT_MODE”);
    startActivityForResult(intent, 0);
    the scan view is opened which covered whole screen. instead of that is it possible to open that event inside any layout which wont cover full screen . so that i can add header and footer at top and bottom
    any help appreciated
    Thank a lot

  109. Icechelsea Says:

    The link you provided actually points to ivy not to ant (download from here http://ant.apache.org/ivy/download.cgi).
    I found ant here:
    http://ant.apache.org/bindownload.cgi
    and an excellent installation guide here:
    http://madhukaudantha.blogspot.com/2010/06/installing-ant-for-windows-7.html
    thanks for the post btw

  110. Faiçal Says:

    Please can any one gave an example an applied work of this example? please please please :)


  111. i’m using Zxing 2.0. I created the jar file with ant, added to project, modified the manifest file , added the code above, but it gives an error : java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mypackage.barcode/com.google.zxing.client.android.CaptureActivity}: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader@44c07928

    Can anyone please upload a working example?
    Thanks advanced.

    • gargi Says:

      Hi Molnar,
      Have you got the solution to your problem.
      I am also facing the same problem.
      Any help would be much appreciated.

  112. Sow Hand Serm Says:

    I used to have this problem(100 errors) where by R.java is not created, until I removed android:xlargeScreens=”true” from android manifest file :D

  113. erikmadsen Says:

    Thanks for this. I’ve got everything working except for one thing. Why is the Android robot logo covering the entire view during the qr code scanner?

  114. erikmadsen Says:

    Thanks for this. Everything is working for me with one caveat: the scanner’s viewport is covered with a gigantic Android robot logo. Any ideas what I’ll have to do to eliminate it?


  115. [...] fosse claro, inclusive no site oficial do ZXing do projeto. Após algumas buscas encontrei esse tutorial do ZXing que explica de forma simples e clara como fazer esta integração. Fiz tudo conforme está [...]

  116. Florian Says:

    Hello,

    unfortunately, it is not working for me. In step 4 I insert the code into my trigger function, but nothing happens and I have no error in Eclipse. I would also be very happy if anyone could post a link to a working sample here, please!
    By the way: Do I have to build the core.jar by myself or will the downloaded core.jar from the zxing-2.0.zip from the ZXing-download section do?

    Thanks,
    Florian

  117. Florian Says:

    Hello,

    is it also possible to use the core.jar from the zxing-2.0.zip which is available from the zxing downlaod section instead of building my own core.jar with ant?
    Being a newbie, it would also be very helpful to have a link to a full working sourcecode in this forum, please!

    Thanks,
    Florian


  118. [...] WiFi Unlocker App for Android ReviewEasy Downloader App for Android ReviewPdt6100Pdt6100Integrate zxing barcode scanner into your Android app natively using Eclipse .wslHeader{ display:inline!important; font-weight: normal!important; text-shadow: none; [...]

  119. Adit Says:

    can u tell me how to checkout the zxing src files? I don’t know how to download & integrate in my project


  120. [...] Sounds really cool but as a developer it is as complicated as qrcode itself  . [...]

  121. Adit Says:

    Is it require that barcode scanner apk ainstalled before proceeding?
    Because my app stops when I click button with VFY error

  122. Luis Alberto Pereira Says:

    Hi everyone,
    I’ve got a problem and would like to know if others also have the same.
    I joined the zxing2.0 to my project. Everything worked well except when I try to scan for PRODUCT_MODE. If I use the application recognizes QR_CODE_MODE if PRODUCT_MODE use the application does not recognize the code.
    Anyone had this problem? If yes, what is the solution.

    Thank you,
    Luiz

  123. rima Says:

    Hi;
    my problem is that my layout does not appear in “graphiqual layaut”. What is the problem help me please :)

  124. Petr Says:

    Thanks. Works fine.

  125. yuvarajang Says:

    its working fine for product bar code. i need it for vin bar code. what are changes need it ?

  126. Renald Says:

    I had an Android Runtime Exception too because a class wasn’t found, and I solved the problem. To add an external Jar with a recent Eclipse version, you need to create a folder libs in your root project, copy/paste the core.jar in this folder and add the core.jar from this folder.

    src : http://stackoverflow.com/a/6859020

    Hope this helps

  127. geek Says:

    Hi, i’m getting error in the codes after importing those files in the project. What is the solution for this ?

  128. Tomd Says:

    Thanks – fantastic tutorial. In addition to the above comment I also found that with the latest ADT tools, I didn’t need to add core.jar to the main project

  129. Adam Says:

    So, I am having trouble with Step 3, no matter what I select it wont let me create from existing source. I tried just doing the core and android folder no luck, so got the whole trunk nothing. Do I need to create a project in Step 2 and then do this?

    • Adam Says:

      Nevermind I’m a dope, I guess I shouldn’t have been trying to configure this at work. I got things configured pretty quickly last night on the computer I will need this for anyway.

  130. Richa Says:

    Hi I have followed all the steps, still some issue is coming and my application is not working. also the apk size is 55mb which is huge. Can we do something to reduce the apk size?

  131. Adam Says:

    Cool after some muddling I finally got this to work, sean isn’t going to be happy as I had to switch his switch statements with ifs and had to check the box for including the core.jar, but at least my reasoning for this project was to save me some time and focus on an app for a good cause. Now I just will have to modify the search from google to my own database as I am checking against specific datasets. Too bad I have to configure this at home now, SHHH!!! It’s kind of work related :D, I blame my director

    • Sean Says:

      You don’t have to change any code, unless you use an outdated Android SDK. You are supposed to include core.jar; how would it work otherwise? I can’t see how this ‘saved you some time” compared to integrating by Intent, which is like 10 lines of code instead of this hassle. You won’t be the first or last to copy and paste everything. Can you at least change the UI and Intents so you’re not pretend you are Barcode Scanner to our users?

      • Adam Says:

        Yea, I am not using this for the main app, just a prototype. I will probably contact you later if I need any assistance doing it the “right” way for the final app. I just don’t have a lot of time this was just told to me the other day and I want to focus on my app not the barcode portion which as you have stated has been don’t so why reinvent the wheel.

        And seeing how I just installed the SDK not sure why you would think I am outdate, it says your code cant be used since ADT 14 I think as I just recalling, but I don’t want to argue. Anyway it works for what I am doing and if this is going to be released beyond my inital use(which I am hoping because it is a very beneficial app for a widely used government program), I will be sure everything is done correctly. I will want to give credit appropriately as I think this will only be at most asking for a optional donation to go to the program if allowed or to who they would like it to go to.

        I am using the core.jar, but the switch case in the android project was what gave the errors, you have seen this in several of these postings, either its the code or the implementation isnt clear. After getting everything setup correctly the actual instructions above only take like 10 minutes to implement, so that’s pretty quick in my book.

        Thanks to you both either way, I will keep you posted.

  132. Sean Says:

    (Regarding if-else — actually your SDK version is not the issue indeed. It’s that you’re targeting a higher level of Android than the project does. You would have to change this code then, yes.)

    • Sean Says:

      Nope, I’m wrong there again. Now I remember, having read up on the internet again. It’s because the app is not a library project, but if you use it as such, you would have to make this code change as of SDK14. Obviously, it’s not intended to be used that way, so it’s not written to work with this use case.

    • Adam Says:

      Cool thanks for explaining.

  133. prabhakr Says:

    any body help me how to use zxing in my new android application….
    please reply…

  134. prabhakr Says:

    I Need Full Support for develop barcode scanner in android..

  135. Sankar Says:

    onActivityResult not calling……pls tell the solution..

  136. febros Says:

    Hey thanx for this good guide. I followed all the steps, but a got an error message after starting the intent. My Logcat told me, that it is unable to find the classes. I received the messages:

    trying to launch com.febros.barcodetest/com.google.zxing.client.android.CaputreActivity

    after that i receive the message:

    unable to resolve static field 1007 (ISSUE_Number) in /com/google/zxing/ResultMetadataType;

    ….

    I created a new project from existing code. Defined this project as a lib and add the extern core.jar, I created before with ant. My own project imported the lib fom zxing.

    By the way I was thinking, that the IDE (Eclipse) is not working well and I decompilded the classes.dex from the apk file. But the classes CameraActivity is in the bundle. The Activity is also in the Mainfest implemented.

    Please help me out I trying to find a solution since 2 days.

  137. Bondax Says:

    To be more robust use this when defining your intent:

    Intent intent = new Intent(com.google.zxing.client.android.Intents.Scan.ACTION);
    intent.putExtra(com.google.zxing.client.android.Intents.Scan.MODE,
    com.google.zxing.client.android.Intents.Scan.QR_CODE_MODE);

    This way you don’t have to react on changes in arbitrary strings.

  138. Chris Says:

    :))) Thanks alot… This is all I neede to help me make some quick money… THanks alot


  139. I want to integrate zxing library in my android app but I don’t want to use intent based approach. Please help me solve this problem. Maybe you know some useful link how for tutorial

  140. Dicky Says:

    Hello, I want to know if i execute success, the barcode scanner will be build up in my application? (which mean when I use the barcode scanner function in my application, we don’t need to download the barcode scanner separately and the application can also run normally?)

  141. Aris Says:

    This has helped me a lot, but I am still stuck.

    After I get the barcode scanner up, it scans, but then just says “found url” and then returns to the index of my webview app template.

    I am not sure how to get the scanner to open the results in my the apps webview, I can post a link to the source files if someone can help me in anyway

    Thanks!


  142. [...] work as a solo application so it crush evrytime i start it. I do evry thing as in followed tutorial http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app… however, it somehow doesn’t work. So i tryied to start the captureActivity as application [...]

  143. Cora Hui Says:

    Sorry, how can i download the source code?? I don’t know how to download using svn.

  144. nicodio Says:

    I followed these steps but in my project, under Java Build Path come out an error on android Dependencies saying that com.google.zxing.client.android.captureactivity.jar is missing.

    What am I doing wrong?

  145. JJ Says:

    works nicely..thanks for the guide

    • MG Says:

      hey, I followed the guide and it didn’t work. I rechecked everything and all seems fine until I press the scan button.

      Once I scan, it all just stops and device says App stopped. Logcat reports errors which I’m unable to follow.

      I’m a newbie to android development. Is there anything you did other than the steps mentioned above ?

  146. mitja Says:

    Well i’m having a problem i download and build app, import core.jar and try to run is as stand alone application but it crashes when loading metadata. Any idea why?

  147. rajagopal Says:

    very informative guidance. It worked perfectly without single error. Thanks a lot.

    One question do we want to have third party QR scanner installed to make this work.


  148. Hi am testing the app after following the steps above. Unluckily it is not working, the app launches, but as soon as i click on the Scan button, the app suddenly stops. I’ve followed all steps mentioned. Please help me

  149. ryan Says:

    I Keep getting resource errors.

    ZXing/src/com/google/zxing/client/android/CaptureActivity.java:326: constant expression required
    case R.id.menu_share:

    any help on this?

  150. Jimmy Says:

    Hi everyone,

    I setup successfully. But when I run app and hover the qr code or barcode, i can’t get any information about the qr code or barcode. It’s just show the image of the qr code (barcode) that it’s recognize and the text “found plain text” or “found product” then close my app immediately.
    All the things I need is the information of the product.

    Any idea for this problem would be appreciate.
    Thanks a lot.


  151. [...] bien, par contre il va falloir se remettre à Java et ça pas être de la tarte je pense. Un petit tuto sympa. Tout ça pour essayer de reprendre mon [...]

  152. kirti avaiya Says:

    I follow same step but i got an error while i run in eclipse emulator like PACKAGE NAME stopped unexpectedly..so how can i solve this error.

  153. Toonioo Says:

    Thanks so much !
    Works so good !
    Congratulations

  154. blunder Says:

    Hi I followed the guide line by line but when I execute the application I get fatal exception upon clicking the scan button. The Logcat record is as followed :

    12-13 12:36:06.781: E/AndroidRuntime(2493): FATAL EXCEPTION: main
    12-13 12:36:06.781: E/AndroidRuntime(2493): java.lang.RuntimeException: Unable to resume activity {com.site.myscanner/com.google.zxing.client.android.CaptureActivity}: java.lang.NullPointerException
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2564)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2607)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2088)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.ActivityThread.access$600(ActivityThread.java:134)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.os.Handler.dispatchMessage(Handler.java:99)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.os.Looper.loop(Looper.java:137)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.ActivityThread.main(ActivityThread.java:4697)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at java.lang.reflect.Method.invokeNative(Native Method)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at java.lang.reflect.Method.invoke(Method.java:511)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at dalvik.system.NativeStart.main(Native Method)

    12-13 12:36:06.781: E/AndroidRuntime(2493): Caused by: java.lang.NullPointerException
    12-13 12:36:06.781: E/AndroidRuntime(2493): at com.google.zxing.client.android.CaptureActivity.onResume(CaptureActivity.java:163)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.Activity.performResume(Activity.java:4607)
    12-13 12:36:06.781: E/AndroidRuntime(2493): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2546)
    12-13 12:36:06.781: E/AndroidRuntime(2493): … 12 more

  155. Ajinkya Says:

    Hello, i downloaded the android\ dir, and i imported it in eclipse. But is showing a lot of errors in that project. Help me out.

  156. rkjhaw Says:

    Hi,
    This piece of code for QR Scanner not for Bar Code scanner,
    Because this code can read QR code, not bar code.

    Can any let me know, how to scan Bar code. please share me details
    r
    Thanks in adv.
    rkjhaw@hotmail.com

  157. viru48 Says:

    this post inspired me a lot….thanks to the author.
    how can i use a scan type(red line moving across the screen) process in my application to create a scanning of things perception.

  158. Dilshad Says:

    01-03 10:28:15.445: E/AndroidRuntime(3405): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) }
    ==================================================== I am getting this exception. What is going on with my code. I can’t use :- IntentIntegrator integrator = new IntentIntegrator(shopping.this);
    integrator.initiateScan();
    In my project

  159. Dilshad Says:

    Please take me out of this issue..

  160. Alberto Says:

    Has anyone tried this tutorial successfully with version 2.1 of ZXing?


  161. “Integrate zxing barcode scanner into your Android app natively
    using Eclipse | Damian Flannery’s Blog” was a extremely pleasant post, . Keep authoring and I will continue reading through! I appreciate it -Charline


  162. [...] create an app that integrating zxing. I followed as per this site http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app…. Now i have error in drawable folder. Please guide [...]

  163. Raj Says:

    I would first like to thank you so much for a wonderful job you did. Well, I have no problem with the code, but I tried installing it on Nexus 7. The installation was successful but I didn’t get any OPEN option after installing which we generally should get. I also couldn’t find the application in my application list on my Tablet. Is there anything I have to do to make it work on Nexus 7?

  164. kamaleon70 Says:

    The provided information was very useful to me, but I had to solve two problems. The first war related to the fact that the switch-case statement cannot be more used with resources (it is necessary to replace it with “if-else” statement). The way to fix the problem in the ZXing 2.1 files is described following this link:
    http://tools.android.com/tips/non-constant-fields
    The other problem was that the app crashed the first time after installing it. This was because the function “showHelpOnFirstLaunch” was called, generating the crash of the app. I have commented this call in onCreate in CaptureActivity.java.
    After these two changes everything worked for me.

  165. Piyush Gupta Says:

    Great article, just (Feb 2013) built an app with it, couple of updates to share. 1 – The new SDK requires certain switch statements in CaptureActivity source be converted to if-else. Just look at the redX’s, click cursor on switch and do Ctrl-1 (number one) and SDK does it for you. Otherwise the app won’t launch from my app. 2 – The changes in the manifest as shown above, if you already have a MAIN LAUNCHER in your app, you may want to make zxing app without the MAIN intent-filter or you get two icons in your device. In that case, delete the MAIN intent-filter in zxing activity and add android:exported=”false” in the activity tag. 3-Just fyi, other scan modes besides QR_CODE_MODE are ONE_D_MODE (for code128, UPC etc), PRODUCT_MODE (for UPC) and DATA_MATRIX_MODE.


  166. Awesome tutorial, i just make barcode scanner !
    but i think you must add core.jar in the lib folder on your project directory. because when i only add in the build path, my apps going force close, and i try to add core.jar in the lib folder directory.

    thank you damian !

  167. Ravi Teja Says:

    Thanks for the wonderful article.

    However, I am getting a pop of complete action by in my mobile after clicking the button. Any help ?

  168. suprit12 Says:

    Can someone help me i m getting the following errors in logcat during executing…

    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to resolve static field 1460 (ISSUE_NUMBER) in Lcom/google/zxing/ResultMetadataType;
    03-17 11:50:14.785: D/dalvikvm(27807): VFY: replacing opcode 0×62 at 0×0017
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/ResultPoint;)
    03-17 11:50:14.785: I/dalvikvm(27807): Could not find method com.google.zxing.ResultPoint.getX, referenced from method com.google.zxing.client.android.CaptureActivity.drawLine
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to resolve virtual method 3987: Lcom/google/zxing/ResultPoint;.getX ()F
    03-17 11:50:14.785: D/dalvikvm(27807): VFY: replacing opcode 0x6e at 0×0000
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.785: I/dalvikvm(27807): Could not find method com.google.zxing.Result.getResultPoints, referenced from method com.google.zxing.client.android.CaptureActivity.drawResultPoints
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to resolve virtual method 3983: Lcom/google/zxing/Result;.getResultPoints ()[Lcom/google/zxing/ResultPoint;
    03-17 11:50:14.785: D/dalvikvm(27807): VFY: replacing opcode 0x6e at 0×0003
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.785: I/dalvikvm(27807): Could not find method com.google.zxing.Result.toString, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeExternally
    03-17 11:50:14.785: W/dalvikvm(27807): VFY: unable to resolve virtual method 3986: Lcom/google/zxing/Result;.toString ()Ljava/lang/String;
    03-17 11:50:14.785: D/dalvikvm(27807): VFY: replacing opcode 0×74 at 0x007d
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.790: I/dalvikvm(27807): Could not find method com.google.zxing.Result.getBarcodeFormat, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecodeInternally
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to resolve virtual method 3980: Lcom/google/zxing/Result;.getBarcodeFormat ()Lcom/google/zxing/BarcodeFormat;
    03-17 11:50:14.790: D/dalvikvm(27807): VFY: replacing opcode 0×74 at 0x004c
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.790: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: I/dalvikvm(27807): Could not find method com.google.zxing.Result.getText, referenced from method com.google.zxing.client.android.CaptureActivity.handleDecode
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to resolve virtual method 3984: Lcom/google/zxing/Result;.getText ()Ljava/lang/String;
    03-17 11:50:14.795: D/dalvikvm(27807): VFY: replacing opcode 0x6e at 0×0070
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.795: W/dalvikvm(27807): VFY: unable to find class referenced in signature (Lcom/google/zxing/Result;)
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b7 at 0×19 in Lcom/google/zxing/client/android/CaptureActivity;.
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b3 at 0x1b in Lcom/google/zxing/client/android/CaptureActivity;.
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b6 at 0x1d in Lcom/google/zxing/client/android/CaptureActivity;.
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05ac at 0x3c in Lcom/google/zxing/client/android/CaptureActivity;.drawResultPoints
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05a6 at 0×44 in Lcom/google/zxing/client/android/CaptureActivity;.drawResultPoints
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b8 at 0xb1 in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeExternally
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b8 at 0xbd in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeExternally
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b5 at 0xd0 in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeExternally
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b3 at 0xe9 in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeExternally
    03-17 11:50:14.800: I/dalvikvm(27807): DexOpt: unable to optimize static field ref 0x05b2 at 0xfc in Lcom/google/zxing/client/android/CaptureActivity;.handleDecodeExternally
    03-17 11:50:14.805: W/dalvikvm(27807): Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/google/zxing/client/android/CaptureActivity;
    03-17 11:50:14.805: W/dalvikvm(27807): Class init failed in newInstance call (Lcom/google/zxing/client/android/CaptureActivity;)
    03-17 11:50:14.805: D/AndroidRuntime(27807): Shutting down VM
    03-17 11:50:14.805: W/dalvikvm(27807): threadid=1: thread exiting with uncaught exception (group=0x40c321f8)
    03-17 11:50:14.805: E/AndroidRuntime(27807): FATAL EXCEPTION: main
    03-17 11:50:14.805: E/AndroidRuntime(27807): java.lang.ExceptionInInitializerError
    03-17 11:50:14.805: E/AndroidRuntime(27807): at java.lang.Class.newInstanceImpl(Native Method)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at java.lang.Class.newInstance(Class.java:1319)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.app.Instrumentation.newActivity(Instrumentation.java:1026)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1883)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.app.ActivityThread.access$600(ActivityThread.java:127)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.os.Handler.dispatchMessage(Handler.java:99)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.os.Looper.loop(Looper.java:137)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at android.app.ActivityThread.main(ActivityThread.java:4507)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at java.lang.reflect.Method.invokeNative(Native Method)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at java.lang.reflect.Method.invoke(Method.java:511)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
    03-17 11:50:14.805: E/AndroidRuntime(27807): at dalvik.system.NativeStart.main(Native Method)
    03-17 11:50:14.805: E/AndroidRuntime(27807): Caused by: java.lang.NoClassDefFoundError: com.google.zxing.ResultMetadataType
    03-17 11:50:14.805: E/AndroidRuntime(27807): at com.google.zxing.client.android.CaptureActivity.(CaptureActivity.java:96)
    03-17 11:50:14.805: E/AndroidRuntime(27807): … 15 more

  169. David Lindsley Says:

    Forget about zxing! After spending all day trying to make it work, I finally found Zbar. Excellent! No muss, No fuss! And very lean and mean, as opposed to the rather hefty zxing! All I needed was a way to read QR codes in my app and Zbar was perfect!!


  170. [...] reading capabilities of Zxing into a stand-alone app, and have been using this very helpful guide http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app… along with these pointers Integration ZXing library directly into my Android application but after [...]

  171. Ash Says:

    I’ve got it working but any changes I make to the new ZXing project don’t get applied to my project that uses ZXing… I’ve tried recompiling, deleting the bin folder completely, re-adding the library to new project, etc. Any ideas?

  172. suganya Says:

    Thanks for sharing this article.. I implement this scanner in my application. Intially it work file while i m trying it in my android mobile phone.. but after some time it showing “unfortunately has stopped” while pressing scan qrcode button.. Plz any body help to fix this issue

    • kamaleon70 Says:

      Try to comment the line
      beepManager.playBeepSoundAndVibrate();
      in captureactivity in the zxing library.

  173. Bara'a Says:

    Great tutorial, can I ask you about how to retrieve the the data from a barcode


  174. [...] reading capabilities of Zxing into a stand-alone app, and have been using this very helpful guide http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app… along with these pointers Integration ZXing library directly into my Android application but after [...]

  175. Arianit Says:

    Hello, I have a problem with this implementation. After running my app on my phone it asks me whether I want start it with the installed barcode scanner or my app. if I choose the barcode scanner, everything works fine, but if I choose my app – the app crash :(


  176. [...] damianflannery.wordpress.com/2… [...]


  177. I am extremely impressed together with your writing
    skills and also with the structure for your blog. Is that this a paid theme or did you customize it yourself?
    Either way stay up the nice quality writing, it is uncommon to peer a nice weblog like this
    one nowadays..

  178. Meryl Says:

    I am getting this error on running the app:
    05-08 16:44:59.140: ERROR/AndroidRuntime(988): Caused by: java.lang.ClassNotFoundException: com.google.zxing.client.android.CaptureActivity in loader dalvik.system.PathClassLoader[/data/app/com.scanner.demo-2.apk]

  179. kenichiwam Says:

    This seems to be a bit out of date, but the best guide so far. Core no longer has an ant build. Anyone know what to do with the latest version of ZXING?

  180. Hardik Trivedi Says:

    Tutorial is awesome. I have been here for 3-5 times.
    But intent.putExtra(“SCAN_MODE”, “QR_CODE_MODE”);

    This will scan only QR_CODE. But what about other formats ?

    Is there anything which tells to scan any format like EAN-8, Code 39 etc…

  181. Reuben Ahmed Says:

    They removed core/build.xml from SVN, so your ANT instructions are out of date.


  182. […] laten weten dat het Zxing team mensen afraadt om de library in zijn geheel te implementeren (http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app&#8230; ). De voornaamste redenen die opgevoerd worden […]

  183. Lukis Says:

    weird! cause I see no “core/build.xml’ at all. only “core/pom.xml”
    so how to achieve core.jar?

  184. Kashif Khan Says:

    I have completed the setup and the app starts. But the camera does not get initiated. The debug pointer stops here

    private static final Set DISPLAYABLE_METADATA_TYPES =
    EnumSet.of(ResultMetadataType.ISSUE_NUMBER,
    ResultMetadataType.SUGGESTED_PRICE,
    ResultMetadataType.ERROR_CORRECTION_LEVEL,
    ResultMetadataType.POSSIBLE_COUNTRY);

    in the com.google.zxing.client.android.CaptureActivity.java

    Any idea what is the problem?


  185. I scarcely make remarks, however I read over a ton of
    reviews here on Integrate zxing barcode scanner into your Android
    app natively using Eclipse | Damian Flannery’s Blog
    but had some requests for you if you don’t mind. Could
    it be just me or are some of the replies appear as if they’re coming from brain dead individuals?
    And, should you be publishing on other supplemental webpages, I’d like to stay in touch with you.
    Would you put up a short list of all of your current social media sites including
    linkedin account, Facebook page or twitter feed?

  186. Danersido Says:

    I have this problem:

    09-10 17:53:35.227: E/AndroidRuntime(3933): Caused by: java.lang.NullPointerException
    09-10 17:53:35.227: E/AndroidRuntime(3933): at com.google.zxing.client.android.CaptureActivity.resetStatusView(CaptureActivity.java:632)

    Any idea?

  187. George Petrucci Says:

    I’m also kind of noob. I actually understand every step except the very first one which requires for me to use svn. How do you install subversion? ‘Coz my Windows 7 can’t seem to recognize the file type of its installer. Sorry if this is such a noob question. :))


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 47 other followers

%d bloggers like this: