Skip to content

Scanning a QR Code from an Android App

One of the new features available to Android in Xojo 2023 Release 4 is the Barcode class. With this class you can scan barcodes, such as QR codes, to get their content.

To use Barcode, you can just drag one onto your screen. Add the ScanCompleted event handler, which is called when a code is successfully scanned. You’ll get the result as a string parameter.

Call the Scan method on the screen object. For example, if you’ve dragged a Barcode class onto your screen and named it Scanner you can start scanning like this:

Scanner.StartScan

That opens the system UI for code scanning, activating the camera. When a code is successfully identified and scanned, Scanner’s ScanCompleted event is called with the value provided as a string.

You can then display this value or use it in some way. For example, you could detect if it is a URL and use it with an HTMLViewer.

Here is a sample QR code that has encoded “https://www.xojo.com”. Scan it to see the URL in the TextArea using this Barcode sample project.

Learn more in the Xojo Documentation.

Paul learned to program in BASIC at age 13 and has programmed in more languages than he remembers, with Xojo being an obvious favorite. When not working on Xojo, you can find him talking about retrocomputing at Goto 10 and on Mastodon @lefebvre@hachyderm.io.