Search code examples
androidbarcode-scannerzxing

Basic ZXING library application


I am trying to produce

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
        }
    }
}

Using the libraries therefore not needing to install the software, I have had a look at the application that comes with it, and added CaptureActivity.java to my project to see if I can locate the core scanning loop but it kept just requiring more and more files (ended up with about 28 in total) and after I had no errors it still didn't work.

I am not looking into doing anything fancy, just on a button click open the capture layout, scan a code, return the code.

There are a few examples on how to decode local files but not the actual scanning side of it to detect a actual barcode.

So, what I help with is embedding the scanning code

Thanks


Solution

  • I think you're mixing up two things. The code you have shows you are trying to integrate via Intent, in which case you do not need any project code in your application at all.

    The source in android/ is a complete stand-alone app (Barcode Scanner) and it is not written for you to copy (although the Apache License permits it). What you are doing is not supported, recommended, or encouraged -- integrating via Intent is much easier.

    Write your own app, perhaps looking to the Android source code for inspiration, and that uses the core/ library for scanning. The core scanning happens in DecodeThread.