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.53k stars 505 forks source link

[Enhancement] Add Map.TryOpenAsync - when no map app is found #1289

Closed mbalous closed 2 years ago

mbalous commented 4 years ago

Description

An exception Android.Content.ActivityNotFoundException is thrown when no app to open maps is installed.

Steps to Reproduce

  1. Start Android Emulator
  2. Run code await Map.OpenAsync(location)

Expected Behavior

Nothing or maybe false returned.

Actual Behavior

Exception Android.Content.ActivityNotFoundException thrown

Basic Information

Stack trace ``` {Android.Content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=google.navigation:q=50.0789,14.4244&mode=d flg=0x14001000 } at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <9324da45a6654f83baffa7c2854d836a>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <9324da45a6654f83baffa7c2854d836a>:0 at Android.Content.ContextWrapper.StartActivity (Android.Content.Intent intent) [0x00031] in :0 at Xamarin.Essentials.Map.StartIntent (System.String uri) [0x0002e] in d:\a\1\s\Xamarin.Essentials\Map\Map.android.cs:72 at Xamarin.Essentials.Map.PlatformOpenMapsAsync (System.Double latitude, System.Double longitude, Xamarin.Essentials.MapLaunchOptions options) [0x000c1] in d:\a\1\s\Xamarin.Essentials\Map\Map.android.cs:28 at Xamarin.Essentials.Map.OpenAsync (Xamarin.Essentials.Location location, Xamarin.Essentials.MapLaunchOptions options) [0x0001c] in d:\a\1\s\Xamarin.Essentials\Map\Map.shared.cs:19 at USER_CODE_REDACTED.NavigateInvoked () [0x000e7] in C:\dev\USER_CODE.cs:68 --- End of managed Android.Content.ActivityNotFoundException stack trace ---android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=google.navigation:q=50.0789,14.4244&mode=d flg=0x14001000 } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2007) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673) at android.app.ContextImpl.startActivity(ContextImpl.java:917) at android.app.ContextImpl.startActivity(ContextImpl.java:888) at android.content.ContextWrapper.startActivity(ContextWrapper.java:379) at crc643f46942d9dd1fff9.InnerGestureListener.n_onSingleTapUp(Native Method) at crc643f46942d9dd1fff9.InnerGestureListener.onSingleTapUp(InnerGestureListener.java:79) at android.view.GestureDetector.onTouchEvent(GestureDetector.java:641) at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onTouchEvent(Native Method) at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onTouchEvent(Platform_DefaultRenderer.java:47) at android.view.View.dispatchTouchEvent(View.java:12513) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2705) at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_dispatchTouchEvent(Native Method) at crc643f46942d9dd1fff9.Platform_DefaultRenderer.dispatchTouchEvent(Platform_DefaultRenderer.java:55) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_dispatchTouchEvent(Native Method) at crc643f46942d9dd1fff9.Platform_DefaultRenderer.dispatchTouchEvent(Platform_DefaultRenderer.java:55) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.widget.PopupWindow$PopupDecorView.dispatchTouchEvent(PopupWindow.java:2407) at android.view.View.dispatchPointerEvent(View.java:12752) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5106) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4909) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4585) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4642) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7092) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7061) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7022) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7195) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:326) at android.os.Looper.loop(Looper.java:160) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)} ```
jamesmontemagno commented 4 years ago

This is expected as technically each OS may not have a map app installed or disabled. I will update the documentation to specify the try/catch needed here.

An enhancement my be "TryOpenAsync" like we have done before as a fire/forget

mbalous commented 4 years ago

Yes, TryOpenAsync() would be great, similar to Launcher.TryOpenAsync(string uri).

bares43 commented 3 years ago

@jamesmontemagno I've made PR for that :) https://github.com/xamarin/Essentials/pull/1665

jfversluis commented 2 years ago

Thank you so much for all your time and effort on this one. To make your effort not go in vein I ported it to .NET MAUI as you can see here: https://github.com/dotnet/maui/pull/5834

We won't be able to add this to Xamarin.Essentials anymore unfortunately. Thanks again!