2017-01-16 89 views
0

我使用Xamarin开发Android应用程序。我希望能够当用户打开该链接example://gizmos打开的应用程序,所以我加入这个我manifest文件:Xamarin Android深度链接不工作

<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设备上的邮件应用程序的链接example://gizmos,但我得到的消息:Unable to find application to perform this action

编辑

这是不一样的建议重复的,他们没有使用Xamarin。

+0

[深层链接的意图可能的复制不WO rk](http://stackoverflow.com/questions/24808777/deep-linking-intent-does-not-work) – Demitrian

+0

不是重复。他们甚至没有使用Xamarin。 – Darius

+0

我也有同样的问题,对于我得到类没有发现异常 https://stackoverflow.com/questions/48680875/getting-class-not-found-exception-when-doing-deeplinking-in-xamarin-forms –

回答

2

在Xamarin Android上的活动配置是在活动课

的属性设置例如:

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 shell am start -W -a android.intent.action.VIEW -d "wori://example.com/?id=1234" XamarinAndroidDeepLink.XamarinAndroidDeepLink 

你会发现你的应用程序启动:

enter image description here

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

我建议你给你设计自己的网页和下载谷歌浏览器打开HTML页:

注意:不要使用HTML浏览器打开HTML页

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

下载谷歌浏览器并打开链接:

enter image description here

+0

当我打开链接http://example.com时,它不起作用。我需要为此添加一些“类别”吗? – Darius

+1

@Darius我已编辑答案将DataScheme更改为“wori”。并通过浏览器打开它。不要通过html查看器使用chrome浏览器打开您的html页面。 –

+0

这工作,谢谢!然而,我注意到一些奇怪的事情:当我通过链接打开应用程序时,它会打开一个单独的应用程序(而不是使用已打开的应用程序),因此我打开了同一应用程序的两个。这只发生在我的Nexus 5设备上,(在Galaxy S6上正常工作)。我注意到,当应用程序以这种方式打开时,应用程序的标题不同,它使用程序集名称(或名称空间)...所以我认为这是原因。你知道如何指定使用的名称,以便我可以(可能)避免这种情况? – Darius