Solved

Android application input barcode

Posted on 2014-07-17
5
243 Views
Last Modified: 2014-11-24
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
Comment
Question by:flowerbloom
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:KRUNAL TAILOR
ID: 40203600
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 40204239
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
 
LVL 12

Expert Comment

by:KRUNAL TAILOR
ID: 40204654
Hi Flowerbloom,

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

Thanks & Regards,
Krunal T. Tailor
0
 
LVL 1

Author Comment

by:flowerbloom
ID: 40205025
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
 
LVL 6

Accepted Solution

by:
Rafael I earned 500 total points
ID: 40443069
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I tend toward trying the newest hardware and software.  Thiss sometimes works out to my benefit, and sometimes not.  Because I downloaded and installed Android 5.x (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.htm…
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now