Deep linking in Xamarin Android

Spire Jankulovski 1 Reputation point
2022-09-29T08:18:39.467+00:00

I have a Xamarin app that I want to open when user scans a QR code with the camera app.
I was successful in developing the feature, and it works both on Android and iOS.
The issue that I'm facing is specific to certain devices like Pixel 4XL on Android 13 and Sony Xperia XQ-BT52 on Android 12. There might be other devices also, this are the ones I could test on.

The issue only appears on devices, when I invoke the functionality on simulator(Pixel 4XL) it works as expected
(adb shell am start -W -a android.intent.action.VIEW -d "web-site-url")

The actual issue is, when the camera app scans the QR code, it redirects to the web which has the assetlinks.json. This in turn opens my app on the device ** within** the camera app.

What I have as intent filter in MainActivity.sc is :

[IntentFilter(new[] { Android.Content.Intent.ActionView },    
        DataScheme = "https",    
        DataHost = "web-site-url",    
        DataPathPrefix = "/",    
        AutoVerify = true,    
        Categories = new[] { Android.Content.Intent.ActionView, Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable })]    

and in assetlinks.json:

{    
  "statements": [    
    {    
      "source": {    
        "web": {    
          "site": "web-site-url."    
        }    
      },    
      "relation": "delegate_permission/common.handle_all_urls",    
      "target": {    
        "androidApp": {    
          "packageName": "package-name",    
          "certificate": {    
            "sha256Fingerprint": "[cert hash]"    
          }    
        }    
      }    
    }    
  ],    

246011-microsoftteams-image-4.png

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Spire Jankulovski 1 Reputation point
    2022-10-10T11:22:35.487+00:00

    The solution for me was in the Activity LaunchMode.

    I had SingleTop as a value, but changing it to LaunchMode.SingleTask fixed the issue.

    [Activity(Theme = "@style/MyTheme", ParentActivity = typeof(SplashActivity), LaunchMode = LaunchMode.SingleTask, NoHistory = false)]  
    

    @Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) was of big help in investigating this.

    0 comments No comments