我正在使用https://github.com/dm77/barcodescanner来扫描QR码。但是它根本就无法扫描QR码(handleResult从未被调用)。当我将相机对准QR码时,它也不能扫描代码。
这是我的活动。
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);
}
}
我的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'
}
我已经在清单文件中获取了访问相机的权限,不确定缺少什么。