繁体   English   中英

Xamarin 从相机扫描的二维码深度链接 Android 应用程序

[英]Xamarin deep linking Android app from QR code scanned by camera

我有一个 Xamarin 应用程序,我想在用户使用相机应用程序扫描二维码时打开它。 我成功开发了该功能,它适用于 Android 和 iOS。我面临的问题特定于某些设备,例如 Android 13 上的 Pixel 4XL 和 Android 12 上的 Sony Xperia XQ-BT52。可能还有其他设备另外,这是我可以测试的。

该问题仅出现在设备上,当我调用模拟器(Pixel 4XL)上的功能时,它按预期工作(adb shell am start -W -a android.intent.action.VIEW -d "web-site-url")

实际问题是,当相机应用程序扫描二维码时,它会重定向到具有资产链接的 web。json。 这反过来会相机应用程序中的设备上打开我的应用程序。 这怎么可能,以及如何让我的应用程序在它自己的实例中打开?

我在 MainActivity.sc 中作为意图过滤器的是:

[IntentFilter(new[] { Android.Content.Intent.ActionView },
        DataScheme = "https",
        DataHost = "web-site-url",
        DataPathPrefix = "/",
        AutoVerify = true,
        Categories = new[] { Android.Content.Intent.ActionView, Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable })]

在 assetlinks.json 中:

{
  "statements": [
    {
      "source": {
        "web": {
          "site": "web-site-url."
        }
      },
      "relation": "delegate_permission/common.handle_all_urls",
      "target": {
        "androidApp": {
          "packageName": "package-name",
          "certificate": {
            "sha256Fingerprint": "[cert hash]"
          }
        }
      }
    }
  ],

应用程序在相机应用程序中打开

解决方案是更改 Activity LaunchMode。 我有 SingleTop,将其更改为 SingleTask 开始打开我的应用程序,而不是扫描仪应用程序作为容器

[Activity(Theme = "@style/MyTheme", ParentActivity = typeof(SplashActivity), LaunchMode = LaunchMode.SingleTask, NoHistory = false)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM