Thiru
Thiru

Reputation: 2394

barcode scanner using phonegap plugin without using the barcode library?

I am working on phonegap android application. this is entirely new to me. I want develop an application with barcode scanner. that too it might uses the intent call. That means the barcode intent is called from the java code and once the scanning over the result should be displayed in HTML page.

Upvotes: 0

Views: 1406

Answers (2)

b3ck1
b3ck1

Reputation: 11

Just go to and follow the instructions in the readme file.

After adding this to your project you can use something like

window.plugins.barcodeScanner.scan( function(result) {
        alert("We got a barcode\n" +
                  "Result: " + result.text + "\n" +
                  "Format: " + result.format + "\n" +
                  "Cancelled: " + result.cancelled);
    }, function(error) {
        alert("Scanning failed: " + error);
    }
);

to do the scan.

Upvotes: 1

dhaval
dhaval

Reputation: 7659

This code from a phonegap plugin works as expected:

    public PluginResult execute(String arg0, JSONArray arg1, String arg2) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.setPackage("com.google.zxing.client.android");
    //  intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        ctx.startActivityForResult(this, intent, 0);

        return new PluginResult(PluginResult.Status.OK);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            Log.i("Cordova", "result " + resultCode);
            if (resultCode == Activity.RESULT_OK) {
                String contents = intent.getStringExtra("SCAN_RESULT");
                String format = intent.getStringExtra("SCAN_RESULT_FORMAT");

                Log.i("Cordova", "contents " + contents + ", format " + format);
                // Handle successful scan
            } else if (resultCode == Activity.RESULT_CANCELED) {
                // Handle cancel
                Log.i("Cordova", "scan cancelled");
            }
        }
    }

Tested with Cordova 1.7 and Android 2.2

Upvotes: 2

Related Questions