Solved

Android application input barcode

Posted on 2014-07-17
5
252 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
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.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

770 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