【问题标题】:How to open android app using custom protocol in xamarin如何在 xamarin 中使用自定义协议打开 android 应用程序
【发布时间】:2014-04-01 18:47:34
【问题描述】:

我需要使用 myapp://app 之类的自定义协议打开我的应用程序,我知道如何在 Xcode 中执行此操作。现在我正在 Xamarin 中开发一个 android 应用程序,我想知道是否有在 Xamarin 中做同样的事情。

这是我的第一个 Xamarin Android 项目,所以我不知道如何实现,请帮助

【问题讨论】:

    标签: c# android xamarin.android xamarin custom-protocol


    【解决方案1】:

    就像在 Android 上一样,您应该使用 Intent Filter 来实现该功能, 但这些在 Xamarin.Android 中作为类属性实现,在编译时会在应用清单中为您自动转换为 xml。

    这里有一个例子可以帮助你:

    [Activity (Label = "MainActivity", MainLauncher = true)]
    [IntentFilter (new[]{Intent.ActionMain},
        Categories=new[]{Intent.CategoryLauncher, Intent.CategorySampleCode},
        Icon="@drawable/myicon",
        DataScheme="something",
        DataHost="project.example.com")]
    public class MainActivity : Activity
    {
    }
    

    您可以获取有关 IntentFilters 的更多详细信息in the Xamarin docs

    如果您复制粘贴他们的样本,请注意,它会在那里遗漏一个逗号。所以你不会像我一样搜索太久;-)

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 2020-08-31
      • 2021-05-16
      • 1970-01-01
      • 2014-04-23
      • 2021-07-24
      • 2014-02-21
      • 1970-01-01
      相关资源
      最近更新 更多