Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Android deep linking not working

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.

like image 635
Drake Avatar asked May 14 '26 20:05

Drake


1 Answers

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

like image 126
Mike Ma Avatar answered May 16 '26 10:05

Mike Ma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!