【问题标题】:Xamarin.Android <queries> element but as activity attribute in code insteadXamarin.Android <queries> 元素,但在代码中作为活动属性
【发布时间】:2022-06-29 10:45:55
【问题描述】:

Android 11 添加了可见性功能,该功能需要 android 清单中的元素才能使应用能够深度链接到另一个应用。是否可以在代码中使用属性而不是直接在清单中定义?

意图过滤器示例:

[IntentFilter(
  new[] { Intent.ActionView },
  Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
  DataHost = "mydomain.com",
  DataScheme = "http"
)]

然后我也想在代码中添加元素。原因是我有多个清单,在不同的环境中使用,但我将在元素中定义的多个自定义应用程序方案对于所有环境都是相同的,它们将超过 5 个,所以我不想重复 N 次。

【问题讨论】:

    标签: android xamarin deep-linking


    【解决方案1】:

    如果我对你的问题理解正确,可以参考以下代码:

    try {
        Intent intent = new Intent(ACTION_VIEW, Uri.parse(url));
        // The URL should either launch directly in a non-browser app (if it's the
        // default), or in the disambiguation dialog.
        intent.addCategory(CATEGORY_BROWSABLE);
        intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_REQUIRE_NON_BROWSER);
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        // Only browser apps are available, or a browser is the default.
        // So you can open the URL directly in your app, for example in a
        // Custom Tab.
        openInCustomTabs(url);
    }
    

    更多内容可以参考文档:Fulfilling common use cases while having limited package visibility

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      相关资源
      最近更新 更多