如何从二维码结果中启动隐式意图?

How to launch implicit intent from a QR Code result?

我构建了一个二维码扫描应用程序(用 Kotlin 编写,Android)。它会扫描二维码,然后 return 像这样扫描后 URL。

但是,我希望更进一步,将 QR 码的 return 值实际启动到 Internet 应用程序的搜索引擎中,并让它显示 QR 码的预期结果.我如何让应用程序获得 returned URL 并将用户重定向到预期位置?

这是我的MainActivity.kt供参考:

class MainActivity : AppCompatActivity() {

    private lateinit var codeScanner: CodeScanner

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val scannerView = findViewById<CodeScannerView>(R.id.scanner_view)

        codeScanner = CodeScanner(this, scannerView)

        codeScanner.camera = CodeScanner.CAMERA_BACK
        codeScanner.formats = CodeScanner.ALL_FORMATS

        codeScanner.autoFocusMode = AutoFocusMode.SAFE
        codeScanner.scanMode = ScanMode.SINGLE

        codeScanner.isAutoFocusEnabled = true
        codeScanner.isFlashEnabled = false

        codeScanner.decodeCallback = DecodeCallback {
            runOnUiThread {
                Toast.makeText(this, "Scan result: ${it.text}", Toast.LENGTH_LONG).show()}
        }
        scannerView.setOnClickListener {
            codeScanner.startPreview()
        }
    }

    override fun onResume() {
        super.onResume()
        codeScanner.startPreview()
    }

    override fun onPause() {
        codeScanner.releaseResources()
        super.onPause()
    }
}

我使用 this answer 在我的 MainActivity.kt class 中构建了一个 searchWeb 函数;

fun searchWeb(query: String) {

        val url = "http://www.google.com"
        val intent = Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url))
        startActivity(intent)
        
    }

然后我在我的 codeScanner.decodeCallback 中调用函数,就像这样;

codeScanner.decodeCallback = DecodeCallback {
            runOnUiThread {
                Toast.makeText(this, "Scan result: ${it.text}", Toast.LENGTH_LONG).show()
            }
            searchWeb(it.text)
        }

执行此操作后,启动了隐式意图,QR 应用程序启动了互联网浏览器。