From 45d906c7f69cefda92fd4c2af37fdd32cfa38157 Mon Sep 17 00:00:00 2001 From: engrpanda Date: Mon, 20 May 2024 15:34:03 +0800 Subject: [PATCH] add open external edge --- .../main/java/com/evo/qrgo/MainActivity.kt | 20 ++++++++++++++----- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/evo/qrgo/MainActivity.kt b/app/src/main/java/com/evo/qrgo/MainActivity.kt index c7e6edc..f87031b 100644 --- a/app/src/main/java/com/evo/qrgo/MainActivity.kt +++ b/app/src/main/java/com/evo/qrgo/MainActivity.kt @@ -2,7 +2,9 @@ package com.evo.qrgo import android.Manifest import android.content.Context +import android.content.Intent import android.content.pm.PackageManager +import android.net.Uri import android.os.Bundle import android.view.View import android.widget.Toast @@ -16,8 +18,6 @@ import com.journeyapps.barcodescanner.ScanContract import com.journeyapps.barcodescanner.ScanIntentResult import com.journeyapps.barcodescanner.ScanOptions - - class MainActivity : AppCompatActivity() { private val reqId = 0 @@ -47,14 +47,19 @@ class MainActivity : AppCompatActivity() { // Hide the ImageView after scanning binding.imageView.visibility = View.GONE - RobotApi.getInstance().startNavigation(0, string, 1.0, (10 * 1000).toLong(), mMotionListener) + // Check if the scanned string is a URL + if (string.startsWith("http://") || string.startsWith("https://")) { + openLink(string) + } else { + RobotApi.getInstance().startNavigation(0, string, 1.0, (10 * 1000).toLong(), mMotionListener) + } } private fun showCamera() { val options = ScanOptions() options.setDesiredBarcodeFormats(ScanOptions.QR_CODE) options.setPrompt("Scan QR Code") - options.setCameraId(1) //default 0 back, 1 is front + options.setCameraId(0) //default 0 back, 1 is front options.setBeepEnabled(false) options.setBarcodeImageEnabled(true) options.setOrientationLocked(false) @@ -93,11 +98,12 @@ class MainActivity : AppCompatActivity() { setContentView(binding.root) } - private val mMotionListener: CommandListener = object : CommandListener() { override fun onResult(result: Int, message: String) { if ("succeed" == message) { + // Add any additional success handling here } else { + // Add any failure handling here } } } @@ -111,4 +117,8 @@ class MainActivity : AppCompatActivity() { onBackPressed() } + private fun openLink(url: String) { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + startActivity(intent) + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 976cde3..4c37f93 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - QRgo + QRgo Lucki \ No newline at end of file