7

I have been developing an android app to scan the barcode and QR code and send the results to some other application (HTTP). I have read most of the documentation over internet and here in stack over flow and got it working. I could able to run the stand alone zxing android app on my device, also I could run my own separate android app to use Zxing intent to scan the bar code. But even after reading so many questions here and some of the blogs in internet, I could not get my strict requirements.

I want to achieve following things. 1. I do not want to install a separate barcode scanner app in my device to get my own app to work (to scan the barcode). 2. I used following code

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

and when I run the app in my devide, it asks 'Select the application to complete this action' and it shows 'Google' and 'Google Goggles' and it opens the Google page default camera and scans the barcode. I wanted CaptureActivtiy default capturing page to come (not Google's one) to scan the bar code. 3. I have tried using ZXing in my own app as library but it did not work.

Could you please tell where exactly I am going wrong to get this done ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Raghavendra Nilekani
  • 396
  • 2
  • 10
  • 22
  • 2
    Have you checked [This answer ?](http://stackoverflow.com/a/4854637/1405983) I have used it and resolved same issue. – Hardik Joshi May 08 '13 at 06:17
  • Hey Hardik, Thanks for the reply. Yes I had already went to that page. I had tried that but How to I put dependency to the zxing android project from my own app and How to I create intent in this case ? – Raghavendra Nilekani May 08 '13 at 06:26
  • 1
    Actually it works, but If I don't install the barcode scanner app in my device, it opens in the Google default capturing page to capture the image which is not I wanted. I wanted Zxing's capturing page to come to capture the image. – Raghavendra Nilekani May 08 '13 at 06:48
  • So to add to this. As I understand, the zxing library does not support this feature. You have to use an external application or you have to dig around in the source code and use the source to achieve this effect? – Jay Snayder Oct 27 '14 at 13:28

2 Answers2

20

I found "zxing" complicated to use. Then I tried with "ZBar Android Version Library". It was so simple. You can download the library from here: http://sourceforge.net/p/zbar/news/2012/03/zbar-android-sdk-version-01-released/

Within the downloaded package, there is a very simple example. Just follow it or include the example to your app. Hopefully your task will be done.

shaonAshraf
  • 1,107
  • 1
  • 11
  • 21
  • 2
    Can we use zbar to scan QR code as well ? I tried it did not work. Can we achieve something like this ? – Raghavendra Nilekani May 08 '13 at 07:00
  • 2
    yes...it successfully worked for QRcode when I implemented. First of all, just run the sample app...it is supposed to support QRcode. – shaonAshraf May 08 '13 at 07:20
  • 1
    ya it worked. In this example, the camera app start on a separate activity where camera preview will be displayed on a frame layout. But I wanted to achieve following. When I click on a button from a method within an activity, it should open the camera and scan and give the scanned results to the same method so that I continue from there. How can I achieve this using Zbar ? – Raghavendra Nilekani Jun 10 '13 at 11:14
  • Awesome, I had it integrated in less than 15 minutes, and the scanner is really fast and accurate. – Hugo Matilla Jan 28 '14 at 09:32
  • 1
    Answer to @RaghavendraNilekani: startActivityForResult() http://stackoverflow.com/a/10407371/749393 – Hugo Matilla Jan 28 '14 at 09:38
  • 4
    However, it should be warned that this uses the 'GNU Library or Lesser General Public License version 2.0 (LGPLv2)'. You should be wary of using this in your own source codes, as this may affect what you release and force you to provide open-source code on your entire project. So don't so so with proprietary code. – Jay Snayder Oct 27 '14 at 13:38
  • @shaonAshraf the above link can work to scan barcode as well ? – Erum Jan 24 '15 at 09:22
  • @RaghavendraNilekani the above link can work to scan barcode as well ? – Erum Jan 24 '15 at 09:30
2

You are showing that you want to integrate by Intent. That's the recommended way to do it, and you can make it even easier, and restrict the list of apps that reply with IntentIntegrator. It's about 5 lines of code: https://code.google.com/p/zxing/wiki/ScanningViaIntent

However this contradicts what you're saying about wanting to implement the scanning in your app. You should clarify what you want.

If that's the case, you need to build your own scanning app, and reuse core.jar and perhaps bits of Barcode Scanner in android/. This is not supported -- you're on your own. Please don't clone our app.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • Hi Sean Owen Thanks for the information. I do not want to clone the bar code scanner app. Mine is simple requirement where I want to use bar code scanner app without explicitly installing it in my device. I had looked at IntentIntegrator approach where it clearly tells 'it handles the case where Barcode Scanner is not installed' It not installed, it will ask to install from stores which I don't want. I want to integrate the barcode scanner app within my app so I don't want to install it again onto my device from stores. – Raghavendra Nilekani May 09 '13 at 05:22
  • Hi Sean Owen Thanks for the information. I do not want to clone the bar code scanner app. Mine is simple requirement where I want to use bar code scanner app without explicitly installing it in my device. I had looked at IntentIntegrator approach where it clearly tells 'it handles the case where Barcode Scanner is not installed' It not installed, it will ask to install from stores which I don't want. I want to integrate the barcode scanner app within my app so I don't want to install it again onto my device from stores. Very simple requirements. – Raghavendra Nilekani May 09 '13 at 05:33
  • 3
    I want to build a very simple android app to make use of bar code scanner APIs (within my app) and NOT installing bar code scanner app explicitly. – Raghavendra Nilekani May 09 '13 at 05:35
  • @Sean, I'm interested to hear why you say "Please don't clone our app." Isn't the point of the Apache 2.0 license to enable developers to clone your code as a starting point for their own apps? (assuming full attribution & compliance with the license) While *scanning via intent* is a simple implementation, it is not always ideal from a UX perspective. – Richard Le Mesurier Jul 22 '15 at 14:15
  • 1
    @RichardLeMesurier the Apache 2 license does not grant trademark rights, and releasing a confusingly similar app, with the same name and logo, violates those rights. Not a theoretical problem: people release clones with ads and malware. Beyond that, I personally find copy and paste distasteful compared to innovation on top of the OSS, but that's merely a request. Which authors are entitled to. I heartily dismiss the argument that, because it would be easier or more profitable for others to clone, that authors should feel obligated to give away more of their rights. – Sean Owen Jul 22 '15 at 20:24
  • @Sean wow yes, I see - totally agree. I hadn't seen it from that perspective at all. My idea of 'clone' was more to do with using one OSS app as a foundation to build another one on top of. Thx for clarifying. – Richard Le Mesurier Jul 23 '15 at 06:05