saimohanj2me
saimohanj2me

Reputation: 21

how to develop the "Zxing" Barcode scanner application of PhoneGap android

I have an android application which reads the barcode for this, I used the "Zxing" library its working fine. But, I have another application which is developed in PhoneGap for android.

Now I want to use that Barcode application in this PhoneGap application

If any knows about this let me know

Thanks in advance

Upvotes: 1

Views: 2291

Answers (2)

Estel
Estel

Reputation: 2204

Zxing provides public intents for this. There are some details here but it basically involves:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.setPackage("com.google.zxing.client.android");
        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
        }
    }
}

You'll also want to check to see if the Barcode Scanner app is available, and either disable functionality or prompt the user to install it.

Edit: Obviously, I was being stupid and only half-read. You can integrate using this pre-made plugin.

Upvotes: 0

Related Questions