Xamarin 深层链接问题
Xamarin Deep Linking Issue
我已经设置了一个简单的 Xamarin 应用程序来尝试使用深度链接。当我使用 IOS 模拟器时,深层链接工作得很好。但是在使用 Android 设备进行调试时,我似乎无法让它为 Android 工作。
我已经像这样设置了 MainActivity.cs
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] {
Intent.ActionView,
Intent.CategoryDefault,
Intent.CategoryBrowsable
},
DataScheme = "photocapture",
DataHost = "PhotoCapture",
DataPathPrefix = "/photocapture/")
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
AndroidAppLinks.Init(this);
LoadApplication(new App());
}
}
然后在我的 App.cs
中我有一个覆盖 OnAppLinkRequestReceived
protected override async void OnAppLinkRequestReceived(Uri uri)
{ .... }
在 Android 设备上,我下载了一个 HTML 文件,其中包含以下内容 href
<html>
<head>
<title>Product 12345</title>
</head>
<body>
<a href="photocapture://PhotoCapture.Views.PhotoCapturePage?id=123">Deeplink</a>
</body>
</html>
当我在 Android 设备上单击这个 link 时,应用程序没有打开,OnAppLinkRequestReceived
没有在调试器中捕获。
此外,如果我搜索 android 设备的应用程序名称,它也会显示出来。问题就出在从外部来源深度点击 link 时。
我是漏掉了一步还是做错了什么?
我在 IOS 中使用的 link:
photocapture://PhotoCapture.Views.PhotoCapturePage?id=123
没有在 android 上工作。我必须将 photocapture://
更改为 http://
才能使其正常工作。所以最后的 link 看起来像:
http://PhotoCapture.Views.PhotoCapturePage?id=123
我已经设置了一个简单的 Xamarin 应用程序来尝试使用深度链接。当我使用 IOS 模拟器时,深层链接工作得很好。但是在使用 Android 设备进行调试时,我似乎无法让它为 Android 工作。
我已经像这样设置了 MainActivity.cs
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] {
Intent.ActionView,
Intent.CategoryDefault,
Intent.CategoryBrowsable
},
DataScheme = "photocapture",
DataHost = "PhotoCapture",
DataPathPrefix = "/photocapture/")
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
AndroidAppLinks.Init(this);
LoadApplication(new App());
}
}
然后在我的 App.cs
中我有一个覆盖 OnAppLinkRequestReceived
protected override async void OnAppLinkRequestReceived(Uri uri)
{ .... }
在 Android 设备上,我下载了一个 HTML 文件,其中包含以下内容 href
<html>
<head>
<title>Product 12345</title>
</head>
<body>
<a href="photocapture://PhotoCapture.Views.PhotoCapturePage?id=123">Deeplink</a>
</body>
</html>
当我在 Android 设备上单击这个 link 时,应用程序没有打开,OnAppLinkRequestReceived
没有在调试器中捕获。
此外,如果我搜索 android 设备的应用程序名称,它也会显示出来。问题就出在从外部来源深度点击 link 时。
我是漏掉了一步还是做错了什么?
我在 IOS 中使用的 link:
photocapture://PhotoCapture.Views.PhotoCapturePage?id=123
没有在 android 上工作。我必须将 photocapture://
更改为 http://
才能使其正常工作。所以最后的 link 看起来像:
http://PhotoCapture.Views.PhotoCapturePage?id=123