Xamarin Android 深层链接不起作用

Xamarin Android deep linking not working

我正在使用 Xamarin 开发一个 Android 应用程序。我希望能够在用户打开 link example://gizmos 时打开应用程序,因此我将其添加到我的清单文件中:

<activity    android:name="mynamespace.MyActivity"
android:label="@string/application_name" >
<intent-filter android:label="@string/application_name">
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
  <data android:scheme="http"
        android:host="www.example.com"
        android:pathPrefix="/gizmos" />
  <!-- note that the leading "/" is required for pathPrefix-->
  <!-- Accepts URIs that begin with "example://gizmos” -->
  <data android:scheme="example"
        android:host="gizmos" />

</intent-filter>
</activity>

这直接取自 Android 文档。我尝试在物理 Android 设备上的邮件应用程序中单击 link example://gizmos,但我收到消息:Unable to find application to perform this action

编辑

它与建议的副本不同,它们没有使用 Xamarin。

在 Xamarin android 中 activity 配置设置在 activity class

的属性中

例如:

namespace XamarinAndroidDeepLink
{
    [Activity(Label = "XamarinAndroidDeepLink", MainLauncher = true, Icon = "@drawable/icon")]
    [IntentFilter(new[] { Android.Content.Intent.ActionView },
    DataScheme = "wori",
    DataHost = "example.com",
    DataPathPrefix ="/",
    Categories = new[] { Android.Content.Intent.CategoryDefault,Android.Content.Intent.CategoryBrowsable })]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);    
        }
    }
}

并且您不需要在清单中设置意图过滤器 c# 将帮助您在清单中构建配置。

通过 adb 测试深度link :

adb shell am start -W -a android.intent.action.VIEW -d "wori://example.com/?id=1234" XamarinAndroidDeepLink.XamarinAndroidDeepLink

您会发现您的应用启动了:

有些浏览器无法区分url。他们会在您的客户 url 之前添加 http://,当您在地址栏中输入 url 时,它将使用搜索引擎。

我建议您设计自己的 html 页面并下载 google chrome 打开 html 页面:

注意:不要通过 html 查看者打开 html 页面

<html>
 <head>
  <title>Product 12345</title>
 </head>
 <body>
  <a href="wori://example.com/?id=1234">lalala</a>
 </body>
</html>

下载 Google Chrome 并打开您的 link :