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.
LVL 1
flowerbloomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Android

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.