简体   繁体   English

Xamarin深层链接问题

[英]Xamarin Deep Linking Issue

I have set up a simple Xamarin app to try and use Deep Linking. 我已经设置了一个简单的Xamarin应用程序来尝试和使用深度链接。 The Deep Linking works perfectly when I use the IOS simulator. 当我使用IOS模拟器时,深层链接可以完美地工作。 But I can't seem to get it to work for Android while debugging using an Android device. 但是在使用Android设备进行调试时,我似乎无法使其适用于Android。

I've set up my MainActivity.cs like so 我已经像这样设置了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());
    }
}

Then in my App.cs I have an override for OnAppLinkRequestReceived 然后在我的App.cs我有一个OnAppLinkRequestReceived的替代OnAppLinkRequestReceived

protected override async void OnAppLinkRequestReceived(Uri uri)
{ .... }

On the Android device I've download a HTML file with the following href 在Android设备上,我下载了具有以下href的HTML文件

<html>
 <head>
  <title>Product 12345</title>
 </head>
 <body>
  <a href="photocapture://PhotoCapture.Views.PhotoCapturePage?id=123">Deeplink</a>
 </body>
</html>

When I click this link on the Android device the app is not opening up and the OnAppLinkRequestReceived is not catching in the debugger. 当我在Android设备上单击此链接时,该应用程序没有打开,并且OnAppLinkRequestReceived没有捕获到调试器中。

Also if I search the app name of the android device it does show up. 另外,如果我搜索android设备的应用名称,它也会显示。 The problem is just when clicking deep link from an external source. 问题仅在于单击来自外部源的深层链接时。

Am I missing a step or have I done something wrong? 我错过了一步还是做错了什么?

The link I was using that worked in IOS: 我使用的链接在IOS中有效:

photocapture://PhotoCapture.Views.PhotoCapturePage?id=123

Did not work on android. 在android上不起作用。 I had to change photocapture:// to http:// to get it to work. 我必须将photocapture://更改为http://才能正常工作。 So the final link looked like: 因此,最终链接如下所示:

http://PhotoCapture.Views.PhotoCapturePage?id=123

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

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