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.CanOpenAsync() returns wrong value #1947

Open mdobric opened 2 years ago

mdobric commented 2 years ago

Description

On Android, Launcher.CanOpenAsync() returns wrong value for Google Maps URLs when targeting API level 30 (Android 11). This works fine when targeting API level 29.

Steps to Reproduce

  1. Set Android target framework version to API level 30.
  2. Execute code below
string url = "https://maps.google.com/maps?q=123+Main+Street+Atlanta+GA+30303";
var uri = new Uri(url);
bool canOpen = await Launcher.CanOpenAsync(uri);
Console.WriteLine($"await Launcher.CanOpenAsync(uri) = {canOpen}");

Expected Behavior

Output should be

await Launcher.CanOpenAsync(uri) = True

Actual Behavior

await Launcher.CanOpenAsync(uri) = False

Basic Information

stevenbgoldmine commented 2 years ago

This happens when an app attempts to launch my app as well. Was working previously but seems to have stopped after my tablet (Galaxy Tab A SM-T510 Android 11) was updated to the latest One UI version - 3.1 or I updated to Visual Studio 2022 17.0.5.

elicul commented 2 years ago

I can also reproduce it on a Google Pixel 4a running Android 12

softlion commented 2 years ago

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

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

Duplicate of #1958

bryancass commented 1 year ago

I can confirm this is still an issue in VS Version 17.5.0 Preview 1.0 using Android API 30 emulator.

await Launcher.CanOpenAsync("https://google.com"); returns false. but await Launcher.OpenAsync("https://google.com") opens a browser and goes to google.com.

mattleibow commented 1 year ago

I think this is due to the android os. You will need the query things as mentioned by @softlion

MitchBomcanhao commented 1 year ago

This is definitely still a problem:

on

A workaround seems to be wrapping the Launcher.OpenAsync(uri) method in a try/catch instead of checking "CanOpenAsync".