Reputation: 625
By Using Zxing Library. Adding following dependencies in build.gradle
..
I can scan the QR Code.
implementation 'com.journeyapps:zxing-android-embedded:3.6.0@aar' implementation 'com.google.zxing:core:3.3.3'
I want the scan view to display in my own custom layout.. In my layout I have to show a listview below the scan view and at the top of the layout there is a single line header text.
How to implement this?
Upvotes: 1
Views: 4484
Reputation: 61
You should add a ZXingScannerView to your Layout, i.e.:
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="@+id/scanner"
android:layout_width="wrap_content"
android:layout_height="200dp"/>
And get that view in your onCreate() method.
@Override
public void onCreate(Bundle state) {
...
ZXingScannerView mScannerView = (ZXingScannerView)findViewById(R.id.scanner)
...
}
The activity or fragment have to implement the ZXingScannerView.ResultHandler interface in order to get the QR code.
When you want to start to scan you can create a method similar to this one:
public void startScanner() {
mScannerView.setResultHandler(this);
mScannerView.startCamera();
mScannerView.setFlash(true);
mScannerView.setAutoFocus(true);
}
And finally get the result in the method handleResult(Result rawResult) from ZXingScannerView.ResultHandler interface.
@Override
public void handleResult(Result rawResult) {
....
}
That's it. Hope it helps you
Upvotes: 5