Android : ZXingScannerView by – me.dm7.barcodescanner:zxing:1.9 Does not ScanQR Code

androidqr-code

I Am using a https://github.com/dm77/barcodescanner to scan QR Code.
but it does not scan QR Code at all (handleResult never gets called). When I Focus camera on QR Code it does not scan code.

Here is my activity.

    package education.qrexample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.google.zxing.Result;

import me.dm7.barcodescanner.zxing.ZXingScannerView;

public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{

    private ZXingScannerView mScannerView;
    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new ZXingScannerView(this);   // Programmatically              initialize the scanner view
        setContentView(mScannerView);
        mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
        mScannerView.startCamera();          // Start camera on resume// Set the scanner view as the content view
    }

    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();           // Stop camera on pause
    }

    @Override
    public void handleResult(Result rawResult) {
        Toast.makeText(this,rawResult.getText(),Toast.LENGTH_LONG);
     }
}

My Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "education.qrexample"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'me.dm7.barcodescanner:zbar:1.9'
    compile 'me.dm7.barcodescanner:zxing:1.9'
}

I already have a permission to access a Camera in mainfests file. Not sure What is missing.

Best Answer

remove this compile 'me.dm7.barcodescanner:zxing:1.9' and add only implementation 'me.dm7.barcodescanner:zxing:1.9.8'

and check below activity

public class ScannerActivity extends BaseActivity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mScannerView = new ZXingScannerView(this);   // Programmatically initialize the scanner view
    setContentView(mScannerView);
}
@Override
public void onResume() {
    super.onResume();
    mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
    mScannerView.startCamera();          // Start camera on resume
}

@Override
public void onPause() {
    super.onPause();
    mScannerView.stopCamera();           // Stop camera on pause
}

@Override
protected void onStop() {
    super.onStop();
    mScannerView.stopCamera();
}
@Override
public void handleResult(Result result) {
    Log.e(TAG, result.getText());
    Log.e(TAG, result.getBarcodeFormat().toString());

    String scannedText=result.getText();


}

}

follow below this url