Sunil Kumar Sahoo Sunil Kumar Sahoo - 1 year ago 120
Java Question

How to scan QRCode in android

I found a tutorial on how to scan a barcode. But in my application I have to scan a QR code. How can I a scan QR code in Android?

Answer Source
try {
    Intent intent = new Intent("");
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes

    startActivityForResult(intent, 0);
} catch (Exception e) {    
    Uri marketUri = Uri.parse("market://details?");
    Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);

and in onActivityResult():

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = data.getStringExtra("SCAN_RESULT");
        if(resultCode == RESULT_CANCELLED){
            //handle cancel
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download