Solved

Android application input barcode

Posted on 2014-07-17
5
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Tool to Build Android and iOS App 3 145
will india ph work in usa? 21 116
migrating my whatsapp from iPhone to an Android phone 8 154
Samsung Dex 3 93
Introduction Everyone is using a smartphone these days. Contacts, messages, applications, documents, bookmarks, pictures, videos and other stuff which you created and are present only on your device come under the umbrella called “Personal Data”.…
A short article about problems I had with the new location API and permissions in Marshmallow
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.
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…

738 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