I have seen some example that people code executable code on a QR code like this https://itsmattkc.com/etc/snakeqr/. I wanted to create a QR code that executes the command to open a specific phone application for any phone (android & IOS).
The process will be like this,
My question right now is,
Background A QR code doesn't itself execute anything, at a high level QR code is just a method of serializing an array of bytes into a visual form, the reader can de-serialize the image back into an array of bytes which must then be interpreted.
Generic QR readers will generally assume that the original data represented an encoded string and so will decode the bytes into a string.
The instructions in SnakeQR tell you to use a QR reader that allow you to save the bytes to disk, instead of decoding them into a string, which just demonstrates that the QR code contains binary data and that the data on its own doesn't do anything, the user needs to take that data and complete the next step to action it, but that action is up to the user.
This is when the magic starts to happen, if the QR code represents or contains a URL, then most reader applications will auto-launch a web browser and will navigate to that URL.
In the app development world we can hijack the default behaviour of these QR code readers to interact with the device in 3 ways:
Write a web page that will execute scripts to complete your operation on the device that navigates to that page, host that somewhere globally accessible and store the URL to that page in your QR code.
Use a URI that the device will recognise as an internal location, this post How to launch my android app from a QR reader is describing this process, in the android application API you can define these intents, effectively registering a URI with a specific action.
Write your own proprietary QR Reader application that can natively understand the commands in the QR code and can execute them direct.
In terms of languages that support this, its not a language specific thing, in Android applications the mechanism you want to exploit is Android Intents Tutorial (Android Developers - Intents).
In iOS there have been mixed version of URL bindings over the years, but SiriKit is probably the closest in terms of functionality, its far more restricted than android, but enough to launch apps and pass through arguments.
In Windows OS you can register URI schemes to do the same thing...
When it comes to proprietary logic, we can use all 3 methods to build a seemless experience for the users:
- Make a landing web page with a message like "If you see this page then you should install my app for an enhanced experience..." (on this page there should be instructions for how to find and install your app)
- Make the QR code a URL to the landing page with the parameters that you want passed to the app as URL parameters.
- Build and publish your app, in this app you should register the URI to the landing page with the native device OS so that after the device is installed, your app runs instead of the user going to the landing page. Don't forget to map any parameters as startup arguments for your app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With