From f51d07493c3af043bb3f542d1964aa5f3d3baf44 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Mon, 17 Jun 2019 14:08:24 -0700 Subject: [PATCH] Try catch the uimode manager (#818) --- Xamarin.Essentials/DeviceInfo/DeviceInfo.android.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Xamarin.Essentials/DeviceInfo/DeviceInfo.android.cs b/Xamarin.Essentials/DeviceInfo/DeviceInfo.android.cs index d3d99c2e3..2e7520718 100644 --- a/Xamarin.Essentials/DeviceInfo/DeviceInfo.android.cs +++ b/Xamarin.Essentials/DeviceInfo/DeviceInfo.android.cs @@ -33,8 +33,15 @@ static DeviceIdiom GetIdiom() // first try UIModeManager using (var uiModeManager = UiModeManager.FromContext(Essentials.Platform.AppContext)) { - var uiMode = uiModeManager?.CurrentModeType ?? UiMode.TypeUndefined; - currentIdiom = DetectIdiom(uiMode); + try + { + var uiMode = uiModeManager?.CurrentModeType ?? UiMode.TypeUndefined; + currentIdiom = DetectIdiom(uiMode); + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine($"Unable to detect using UiModeManager: {ex.Message}"); + } } // then try Configuration