Android:ZXingScannerView by - me.dm7.barcodescanner:zxing:1.9 不扫描QR码

San*_*ndy 5 android qr-code

我正在使用https://github.com/dm77/barcodescanner扫描二维码。但它根本不扫描二维码(handleResult永远不会被调用)。当我将相机聚焦在二维码上时,它不扫描代码。

这是我的活动。

    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);
     }
}
Run Code Online (Sandbox Code Playgroud)

我的摇篮

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'
}
Run Code Online (Sandbox Code Playgroud)

我已经有权访问 mainfests 文件中的相机。不确定缺少什么。

小智 0

您应该尝试 Android 移动视觉 api。它易于使用且准确性很高。检查这个 - http://arjunu.com/2015/08/android-barcode-detection-tracking-using-mobile-vision-api/

  • @BoxAndBirdie 链接已失效 (3认同)