3

I am using Xamarin to develop an Android application. 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:

<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. 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

EDIT

It is not the same as the suggested duplicate, they are not using Xamarin.

Drake
  • 2,679
  • 4
  • 45
  • 88
  • Possible duplicate of [Deep-linking intent does not work](http://stackoverflow.com/questions/24808777/deep-linking-intent-does-not-work) – Demitrian Jan 16 '17 at 22:31
  • Not a duplicate. They're not even using Xamarin. – Drake Jan 16 '17 at 22:37
  • I also have the same problem, For me getting class not found exception https://stackoverflow.com/questions/48680875/getting-class-not-found-exception-when-doing-deeplinking-in-xamarin-forms – Sreejith Sree Feb 12 '18 at 09:45

1 Answers1

9

In Xamarin android the activity configuration is set in attribute of the activity class

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.

Test the deeplink by 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 :

enter image description here

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.

I suggest you to design you own html page and download google chrome to open the html page:

Note: Do not open the html page by html viewer

<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 :

enter image description here

Mike Ma
  • 2,017
  • 1
  • 12
  • 17
  • It doesn't work when I open the link http://example.com. Do I need to add something to the `Categories` for this? – Drake Jan 17 '17 at 15:28
  • 1
    @Darius I have edit the answer change the DataScheme to "wori". And open it by browser. Do not open your html page by html viewer use chrome browser. – Mike Ma Jan 18 '17 at 02:01
  • This works, thanks! I noticed something strange however: when I open the app via the link, it opens a separate app (instead of using the same app that's already opened), so I have 2 of the same app opened. This only happens on my Nexus 5 device, (works fine on Galaxy S6). I noticed that when the app is opened like this, the title of the app is different, it's using the assembly name (or namespace)...so I reckon this is why. Do you know how to specify the name to use so that I can (possibly) avoid this? – Drake Jan 18 '17 at 19:28
  • 1
    @Darius maybe in your nexus 5 device the two apps registered the same DataScheme. And app title is setted by attribute `[[Activity(Label = "TITLE")]` maybe you opened another app with the different title. Check the same DataScheme apps. Or change your DataScheme to the special one like `DataScheme="lalala"` – Mike Ma Jan 19 '17 at 01:41
  • I also have the same problem, For me getting class not found exception https://stackoverflow.com/questions/48680875/getting-class-not-found-exception-when-doing-deeplinking-in-xamarin-forms Please suggest a solution for me. – Sreejith Sree Feb 12 '18 at 09:45