Search code examples
androidzxing

Barcode scanner with ZXing library


I am developeing a barcode app. in which captured barcode camera image are decode through ZXing library. so simply i have download jar file and add it as external jar. but my problem is that how can i start use of that class there are no sample code at all. so can you provide me some initial thing so i can easily go through that process.


Solution

  • The way to call the ZXing SCAN Intent from your application, like this:

    public Button.OnClickListener mScan = new Button.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            startActivityForResult(intent, 0);
        }
    };
    
    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
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }
    
    Ref:http://code.google.com/p/zxing/wiki/ScanningViaIntent
    
    Sample code:http://as400samplecode.blogspot.in/2011/09/android-barcode-scanner-using-zxing.html