diff --git a/src/DIPS.Xamarin.UI.Android/Library.cs b/src/DIPS.Xamarin.UI.Android/Library.cs index 7044cdff..caa9ab42 100644 --- a/src/DIPS.Xamarin.UI.Android/Library.cs +++ b/src/DIPS.Xamarin.UI.Android/Library.cs @@ -1,4 +1,5 @@ -using DIPS.Xamarin.UI.Internal.Utilities; +using Android.App; +using DIPS.Xamarin.UI.Internal.Utilities; namespace DIPS.Xamarin.UI.Android { @@ -12,7 +13,7 @@ public static class Library /// /// Method to call at startup of the app in order to keep assemblies and to run other initializing methods in the library /// - public static void Initialize() + public static void Initialize(Activity activity) { if (s_isInitialized) return; Inspector.Instance = new Util.Inspector(); @@ -21,7 +22,7 @@ public static void Initialize() var vibrationService = new VibrationService(); Vibration.Vibration.Initialize(vibrationService); - VibrationService.Initialize(); + VibrationService.Initialize(activity); s_isInitialized = true; } } diff --git a/src/DIPS.Xamarin.UI.Android/VibrationService.cs b/src/DIPS.Xamarin.UI.Android/VibrationService.cs index 54596b65..7a344e9c 100644 --- a/src/DIPS.Xamarin.UI.Android/VibrationService.cs +++ b/src/DIPS.Xamarin.UI.Android/VibrationService.cs @@ -4,7 +4,6 @@ using Android.Content.PM; using Android.OS; using DIPS.Xamarin.UI.Vibration; -using Xamarin.Essentials; namespace DIPS.Xamarin.UI.Android { @@ -115,15 +114,14 @@ public IPlatformFeedbackGenerator Generate() return new PlatformFeedbackGenerator(); } - internal static void Initialize() + internal static void Initialize(Activity activity) { - s_activity = Platform.CurrentActivity; + s_activity = activity; s_hasPermission = s_activity.CheckSelfPermission(Manifest.Permission.Vibrate); } private static bool ShouldVibrate() { - s_vibrator ??= Vibrator.FromContext(s_activity); return true; } diff --git a/src/DIPS.Xamarin.UI/Vibration/Vibration.cs b/src/DIPS.Xamarin.UI/Vibration/Vibration.cs index ecb969ae..0806e35a 100644 --- a/src/DIPS.Xamarin.UI/Vibration/Vibration.cs +++ b/src/DIPS.Xamarin.UI/Vibration/Vibration.cs @@ -1,6 +1,4 @@ -using System; - -namespace DIPS.Xamarin.UI.Vibration +namespace DIPS.Xamarin.UI.Vibration { /// /// Vibration/haptic feedback. diff --git a/src/Samples/DIPS.Xamarin.UI.Samples.Android/MainActivity.cs b/src/Samples/DIPS.Xamarin.UI.Samples.Android/MainActivity.cs index d2362308..8541fbc8 100644 --- a/src/Samples/DIPS.Xamarin.UI.Samples.Android/MainActivity.cs +++ b/src/Samples/DIPS.Xamarin.UI.Samples.Android/MainActivity.cs @@ -28,7 +28,7 @@ protected override void OnCreate(Bundle savedInstanceState) Essentials.Platform.Init(this, savedInstanceState); //Xamarin essentials global::Xamarin.Forms.Forms.Init(this, savedInstanceState); - DIPS.Xamarin.UI.Android.Library.Initialize(); + DIPS.Xamarin.UI.Android.Library.Initialize(this); InternalShared.MobileSettings.Instance = new AndroidSettings(this);