A simple barcode/Qrcode reader app for android
This app uses google api to recognise barcodes or QR codes.
I've also created some kind of library to use barcode reader functionality in your projects.
The library is called BarcodeReader.java and you can find that here BarcodeReader.java
To use that follow thoose simple steps:
- Add thoose two lines to your
AndroidManifest.xml
:
<meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="barcode"/>
<uses-permission android:name="android.permission.CAMERA" />
- Add this other line to your
build.gradle
:
implementation 'com.google.android.gms:play-services-vision:10.0.0'
- Add a surface view to your activity to hold your camera preview
- Create a BarcodeReader object in your activity
BarcodeReader yourBarcodeReader = new BarcodeReader(yourActivity.this, yourSurfaceView);
- Set the BarcodeReaderListener, as shown in the example:
yourBarcodeReader.setBarcodeReaderListener(new BarcodeReader.BarcodeReaderListener() {
@Override
public void onCodeScanned(String yourReadedBarcode) {
//Your code here
//yourReadedBarcode contains the value of the barcode you have read
}
});
- Finally add
java yourBarcodeReader.start();
in your code to start the reader.