- QR Reader
- NFC Reader
- Wallet Tag
Fica em looping continuo, leu, manda um POST para queroir.ai/tags/check Resposta uma mensagem, e piscar a tela verde/vermelho Som diferente na leitura tambem bem interessante
Praticamente a mesma coisa... ^
Usuario muda facilmente modo camera / modo nfc Ou o modo camera sempre ta nfc ativo? Possivel? Mas camera pode ser desligada pra consumir menos bateria
Sera gerado um png/webp pra exibir e colocar na carteira a imagem e o codigo NFC
-
QrCodeScanner.kt: Handles the QR code scanning using ZXing library
scan()
: Opens the camera to scan a QR codehandleScanResult()
: Processes the scan resultsendResultToJavaScript()
: Sends the result back to the web view via JavaScript evaluationpostResultToRails()
: Posts the result to the Rails check route using JavaScript form submission
-
MainActivity.kt: Integrates the QR code scanner with Hotwire Native
- Uses delayed initialization to ensure the WebView is fully loaded
- Implements recursive WebView finding in the view hierarchy
- Adds a JavaScript interface for the QR code scanner
- Sets up the JavaScript environment for callbacks
- Sets a flag to indicate that HotwireNative is available
- Dispatches a custom event to notify the web app
- Handles the scan result in onActivityResult
-
qr_code_scanner_controller.js: Stimulus controller for QR code scanning
- Listens for the 'hotwireNativeAvailable' event
- Checks if running in native app environment
- Registers a callback to receive scan results from the native app
- Handles the scan result and updates the UI
- Posts the result to the server
- Includes retry logic and better error messages
-
TagsController: Rails controller for tag verification
- Handles both GET and POST requests for the check action
- Verifies the validity of the tag based on the QR code
-
check.html.erb: View for the check page
- Displays a button to scan QR codes
- Shows the result of the scan
- Navigate to the check page in the app
- Click the "Escanear Código QR" button
- The native camera will open
- Scan a QR code
- The result will be displayed on the page
- Uses Hotwire Native 1.2.0 for communication between the web view and native code
- Uses ZXing for QR code scanning
- The QR code should contain the tag code that is stored in the database
- Communication between native code and web view is done via JavaScript evaluation
- Form submission is used to post the QR code to the Rails check route
- Uses delayed initialization to ensure the WebView is fully loaded
- Implements recursive WebView finding in the view hierarchy
- Sets a flag and dispatches a custom event to indicate that HotwireNative is available
- Includes retry logic and better error messages
The app requires the following permissions:
android.permission.CAMERA
for camera accessandroid.hardware.camera
feature declaration
These permissions are already included in the AndroidManifest.xml file.