Android QR Code / Bar Code ScannerDuring the development of an android application, sometimes it is required to provide a functionality that scans a QR code or barcode. Scanning the QR code can be done programmatically by using many ways:
Android QR Code Scanner ExampleIn this example, we will scan the QR code of a web URL and Email address, and act on it. Here we will use the Mobile Vision API of Google Play Service to scan the QR code. The Mobile Vision API supports the following formats of the barcode.
Create an activity_main.xml and add the following code. activity_main.xmlCreate an activity_scanned_barcode.xml layout and add the following code. The SurfaceView widget is used for camera source. activity_scanned_barcode.xmlCreate an activity_email.xml layout to perform email action. activity_email.xmlAdd the Google Mobile Vision API in build.gradle file. build.gradleIn the MainActivity.java file, add the following code. By clicking the button btnScanBarcode it call the ScannedBarcodeActivity.java class. MainActivity.javaIn the ScannedBarcodeActivity.java activity class, add the following code. This class scans the QR code through the camera. In this class, we will generate two QR code, one for web URL and another is for an email address. A QR code can be generated from any of QR code generator website. ScannedBarcodeActivity.javaIn the EmailActivity.java class, add the following code. This class performs the email sending task to the address mention in the QR code. EmailActivity.javaAdd the following code in AndroidMenifest.xml file. AndroidMenifest.javaOutput: Next TopicRSS Feed Reader |