0

Possible Duplicate:
Using ZXing to create an android barcode scanning app

I know it is possible to scan a movie and see if the movie is available at the store. How would I do this using zxing? I did look over the links pertaining this and I am having a difficulty time understanding it all. I did download the .apk file and convert it to .zip, but I do not see any classes in the folders. I am really confused and I wish there was a web site that explains how to use zxing to make this possible.

anyone have any web sites they know of that will get me started?

thanks.

Community
  • 1
  • 1
MCarter
  • 53
  • 2
  • 9
  • Android apk's do not contain class files. Al code is combined into the classes.dex file. If you want to reverse engineer an apk file you can use the [android-apktool](http://code.google.com/p/android-apktool/). BTW: This question is identical to this one: http://stackoverflow.com/questions/2050263/using-zxing-to-create-an-android-barcode-scanning-app – Robert Jan 19 '12 at 14:18
  • I do have a quick question. I just tested an app and the app did not use the barcode scanner from zxing because I uninstalled it before I tested it. How does this work? Clearly, some web sites say to use the code and redirect the user to the marketplace...but I do not want to do this. – MCarter Jan 19 '12 at 14:32
  • zxing is not the only barcode engine on the market. Some may be available as JAR library that can be included into your app. Then no external dependency is needed. – Robert Jan 19 '12 at 14:38
  • Robert, that sounds fantastic! Where can I download jar files? Let me get this straight, these jar files will make it so that if the user does not have anything barcode scanner related will not have to install one from the market? – MCarter Jan 19 '12 at 15:06

1 Answers1

1

The easiest way to use zxing is to call it by Intent.

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
startActivityForResult(intent, REQUEST_CODE_SCANNER);

This will launch the scanner activity, if Barcode Scanner is installed. After a barcode is recognized it will return to your activity and call

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    Log.i(TAG, "ACTIVITY RESULT");
    if (requestCode == REQUEST_CODE_SCANNER) {
        if (resultCode == RESULT_OK) {
            // get the scanner/input results
            String result = intent.getStringExtra(SCAN_RESULT);
            String format = intent.getStringExtra(SCAN_RESULT_FORMAT);
        } else if (resultCode == RESULT_CANCELED) {
            // nothing to do
        }
    } 
}

With these values you can then query any database to get information about the scanned product.

You might furthermore check, if the Barcode Scanner is installed. I'm doing this is my own app. If the scanner isn't installed, I give the user the possibility to launch the Android Market with the Barcode Scanner App preselected, so he just needs to hit "Download".

henrik
  • 708
  • 7
  • 14
  • thank you henrik for your reply. Would I have to create a new android project? I would like to keep everything in one project if possible. If I do keep it in one project, should I create a new class and a new xml file? I am so lost! thanks for your input. – MCarter Jan 19 '12 at 15:08
  • 1
    You don't need to create a new project. Just add the code to your existing activity, where you want to launch the scanner. For example in an OnClickListener of a button or something like that. – henrik Jan 19 '12 at 19:18
  • thank you. so do I need to come up with something in xml? – MCarter Jan 19 '12 at 20:28
  • I don't exactly know, what you are meaning, but if you have an existing and working activity, you don't need to change anything on your project. You can just add the code to your activity and it should work. The only thing you have to make sure is, that Barcode Scanner is installed on your device. – henrik Jan 19 '12 at 20:50
  • ok. thanks. I will try this out tomorrow when I arrive back to work. take care. – MCarter Jan 19 '12 at 21:25