views:

363

answers:

2

I'm trying to add ZXing to my project (add a button which calls the scanner upon press). I found this: http://groups.google.com/group/android-developers/browse_thread/thread/788eb52a765c28b5 and of course the ZXing homesite: http://code.google.com/p/zxing/, but still couldn't figure out what to include in the project classpath to make it all work!

As for now, I copied the classes in the first link to my project (with some package name changes), and it runs but crashes after pressing the button and trying to install the barcode scanner.

Some code:

private void setScanButton(){
    Button scan = (Button) findViewById(R.id.MainPageScanButton);
    scan.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            IntentIntegrator.initiateScan(MyActivity.this);
        }
    });
}

Resulting error (from logcat):

06-13 15:26:01.540: ERROR/AndroidRuntime(1423): Uncaught handler: thread main exiting due to uncaught exception
06-13 15:26:01.560: ERROR/AndroidRuntime(1423): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://search?q=pname:com.google.zxing.client.android }

Ideas?

+1  A: 

First, ZXing will not be able to automatically prompt the user to download from the Market on an emulator, because there is no Market on the emulator. You would need to manually install the Barcode Scanner APK on the emulator.

Second, since the emulator does not emulate a camera, Barcode Scanner probably will not do you much good. Most likely you are going to need to test this out on a device.

CommonsWare
A: 

Go to http://goo.gl/mgIi For links

In the activity that you want to trigger a barcode scan include

IntentIntegrator.initiateScan(YourActivity.this);

and then also include:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
            TextView 
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
};

The Barcode Scanner app will handle the actual scanning. If the Barcode Scanner app is not installed, the integrator will prompt them to install it.

----------- From nEx.Software ---------------

Zeroows