2017-01-16 93 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