简体   繁体   English

Xamarin Android深层链接不起作用

[英]Xamarin Android deep linking not working

I am using Xamarin to develop an Android application. 我正在使用Xamarin开发Android应用程序。 I want to be able to open the app when the user opens the link example://gizmos , so I add this to my manifest file: 我希望能够在用户打开链接example://gizmos时打开应用程序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>

This is taken directly from the Android documentation. 这可以直接从Android文档中获取。 I try to click on the link example://gizmos from the mail application on my physical Android device, but I get the message: Unable to find application to perform this action 我尝试点击我的物理Android设备上的邮件应用程序中的链接example://gizmos ,但是我收到消息: Unable to find application to perform this action

EDIT 编辑

It is not the same as the suggested duplicate, they are not using Xamarin. 它与建议的副本不同,它们不使用Xamarin。

In Xamarin android the activity configuration is set in attribute of the activity class 在Xamarin android中,活动配置在活动类的属性中设置

For example: 例如:

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);    
        }
    }
}

And you do not need to set the intent filter in the Manifest the c# will help you to build the configuration in the manifest. 而且您不需要在Manifest中设置intent过滤器, c#将帮助您在清单中构建配置。

Test the deeplink by adb : 通过adb测试深层链接:

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

You will find your app start : 你会发现你的应用程序开始:

在此输入图像描述

Some Browser can not distinguish the url. 有些浏览器无法区分网址。 They will add http:// before your customer url and when you input the url in the address bar it will using the search engine. 他们将在您的客户网址之前添加http:// ,当您在地址栏中输入网址时,它将使用搜索引擎。

I suggest you to design you own html page and download google chrome to open the html page: 我建议你设计自己的html页面并下载google chrome来打开html页面:

Note: Do not open the html page by html viewer 注意:不要通过html查看器打开html页面

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

Download Google Chrome and open your link : 下载谷歌浏览器并打开您的链接:

在此输入图像描述

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

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