xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 505 forks source link

[Bug] Launcher TryOpenAsync returns false, OpenAsync returns true #1958

Open lhughey opened 2 years ago

lhughey commented 2 years ago

Description

The TryOpenAsync isn't returning true when appropriate. This is an issue because there is no way to know if app open request fails and the user should be redirected to the app store.

As a result, the following logic cannot be used if(await Launcher.TryOpenAsync(appSchemeUri)) Launcher.OpenAsync(appSchemeUri); else Launcher.OpenBrowser(appStoreFallbackLink);

Steps to Reproduce

  1. Install App1 on Droid (Samsung s10 running Droid 11), set URI scheme in App1 so it can be opened by App2 (which is the app will will be modifying to open App1). Use the scheme format "app1://" when passing to the launcher.

  2. Add the following line in a command or codebehind in App2 var ok = await Launcher.TryOpenAsync(App1URIScheme); //The response of 'ok' is false and App1 doesn't open

  3. Comment out the previous line (in step 2) and replace with the following line in App2

  4. await Launcher.OpenAsync(App1URIScheme); //App1 opens on device

Expected Behavior

Line2 above - should return True and open App1 as OpenAsync opens the app

Actual Behavior

Line2 above - returns False and does not open App1.

Basic Information

WilkoSki commented 2 years ago

I can confirm the issue is present in Xamarin.Essentials v1.7.1 too.

This only seems to affect Android 11, earlier versions behave as expected.

softlion commented 2 years ago

Is that more related to the new "queries" attribute required for app targeting api 30 ?

https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

catapedamania commented 1 year ago

Is that more related to the new "queries" attribute required for app targeting api 30 ?

https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

@softlion, if it is to do with the queries attribute, I have

  <queries>
    <package android:name="com.google.android.apps.maps" />
  </queries>

in my manifest but what URI scheme is called with CanOpenAsync (or TryOpenAsync)? I tried comgooglemaps:// as per https://stackoverflow.com/questions/30884292/google-map-direction-using-comgooglemaps but still doesn't work.