Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Android application input barcode

I am building an Android application where the user can input a barcode and I provide details about the item, similar to MyFitnessPal application.

I can get the application working where the user can enter the barcode manually.  I would like the user to be able to scan the barcode instead of typing it.  The scanning should be done either by using the phone camera (preferred) or an external barcode reader.

I looked at ZXing but I got very confused.  I probably just need the JAR file.

Please provide a detailed simple project example, including activity to accomplish this.

Thank you.
0
flowerbloom
Asked:
flowerbloom
  • 2
  • 2
1 Solution
 
flowerbloomAuthor Commented:
Hi Krunal,

I cannot get these examples to work.  I get errors like "class not found".  I probably miss something that these tutorials assume I should do.

Do you have a downloadable working example with ZXing or Zbar?

Thanks,
Flowerbloom
0
 
KRUNAL TAILORFreelance Mobile DeveloperCommented:
Hi Flowerbloom,

I have not the code but you can try this.
https://github.com/dm77/ZBarScanner

Thanks & Regards,
Krunal T. Tailor
0
 
flowerbloomAuthor Commented:
I saw that example. It is old.  He is using ZXing now also with added features for the Zbar.

Is there any chance you can create an example and send it to me?

My problem is not that I am not aware of ZXing (see original question), but that I cannot get the examples to work with it.

I need something complete.

Thanks.
0
 
Rafael ISolutions EngineerCommented:
Using ZXing is really, really easy.

https://github.com/zxing/zxing/wiki/Scanning-Via-Intent

Download the first two files that are linked in that article: IntentIntegrator.java and IntentResult.java.

Then create a similar folder structure to the package name.  that means in your project folder, create a folder in src called "com" then create a folder inside com called "google" then create a folder inside google called "zxing" then create a folder inside zxing called "integration" then create a folder inside integration called "android" and then inside that folder, copy those two files that you downloaded. so that should be 5 nested folders, not 5 separate folders.

Then in your IDE, include those two files in your project, and in your main code where you want to scan something, import com.google.zxing.integration.android.IntentIntegrator and com.google.zxing.integration.android.IntentResult at the top.

Finally, in your code, wherever you have your onClick function, include the lines
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();

Open in new window


these two lines are responsible for turning the camera on, recognizing the barcode, and returning the scanned barcode to your application.

you will then need to add this function to your Activity function as well
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
  if (scanResult != null) {
    // handle scan result
  }
  // else continue with any other code you need in the method
  ...
}

Open in new window

This will handle the result returned from the scan.  It runs as soon as a barcode is scanned and detected, or if the user cancels the scan with the back button.  You can then notify the user or store the variable as needed.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now