问题
I'm trying to integrate barcode scanner in my android app.
These are the things i have done:
1) i added core-3.2.1 module to my project. 2) added an activity
<uses-permission android:name="android.permission.CAMERA" />
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape" >
</activity>
I'm getting that Cannot resolve symbol 'CaptureActivity'. What should i do more?
I have checked other stackoverflow posts but i'm unable to fix this.
回答1:
You can add zxing library to your app via gradle dependency
just add this to your build.gradle
file
compile 'com.google.zxing:core:3.2.1'
compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'
Now in your onCreate method of your activity , do the following
IntentIntegrator scanIntegrator = new IntentIntegrator(MainActivity.this);
scanIntegrator.setPrompt("Scan a Barcode");
scanIntegrator.setBeepEnabled(true);
scanIntegrator.setOrientationLocked(true);
scanIntegrator.setBarcodeImageEnabled(true);
scanIntegrator.initiateScan();
You can find a sample project here
回答2:
make sure you use give dependencies in app.gradle file than use scanner view for scan barcode
dependencies {
compile 'me.dm7.barcodescanner:zxing:1.8.3'
}
ZXingScannerView mScannerView = new ZXingScannerView(this);
Handler handlerThread = new Handler();
handlerThread.post(new Runnable() {
@Override
public void run() {
mScannerView.setResultHandler(new ZXingScannerView.ResultHandler() {
@Override
public void handleResult(Result result) {
Log.e(TAG, result.getText());
}
});
}
});
回答3:
Make sure you have added module reference into your project. 1) New -> Import new Module -> Select your zxing library. Let the gradle build.
Then, Go to File -> Project Structure -> Select app under modules -> Go to Dependency tab -> add zxing module by clicking on green add button.
Rebuild your project
来源:https://stackoverflow.com/questions/37807777/integrating-zxing-barcode-scanner-to-my-android-app