Search code examples
androidbuttonzxing

Zxing barcode scanner doesn't open from my app


I've integrated Zxing barcode scanner by adding the package com.google.zxing.integration.android into my project and this code on my MainActivity.java file:

public static Button scanBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    scanBtn = (Button) findViewById(R.id.scan_button);

    scanBtn.setOnClickListener(this);
}

public void onClick(View v) {
    IntentIntegrator scanIntegrator = new IntentIntegrator(this);
    scanIntegrator.initiateScan();
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    ...
}

For some reason, when I click at the button (scanBtn) nothing happens. There is nothing in the log, and nothing happens on the screen.

Could you please help me?


Solution

  • I've added a permission for the camera and it solved it.