Skip to content

Commit

Permalink
fix: Auto fallback to vibration on Android haptics
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jul 6, 2021
1 parent ebbab93 commit 4750cfc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Uno.UWP/Devices/Haptics/SimpleHapticsController.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Collections.Generic;
using Android.App;
using Android.Views;
using Android.Provider;
using Microsoft.Extensions.Logging;
using Uno.Extensions;
using Uno.UI;
using PhoneVibrationDevice = Windows.Phone.Devices.Notification.VibrationDevice;

namespace Windows.Devices.Haptics
{
Expand All @@ -33,7 +35,16 @@ public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback)
{
var activity = (Activity)ContextHelper.Current;
var androidFeedback = FeedbackToAndroidFeedback(feedback);
activity.Window?.DecorView.PerformHapticFeedback(androidFeedback);
bool hapticFeedbackEnabled = Settings.System.GetInt(activity.ContentResolver, Settings.System.HapticFeedbackEnabled, 0) != 0;
if (hapticFeedbackEnabled)
{
var executed = activity.Window?.DecorView.PerformHapticFeedback(androidFeedback) ?? false;
if (!executed && PhoneVibrationDevice.GetDefault() is { } vibrationDevice)
{
// Fall back to VibrationDevice
vibrationDevice.Vibrate(feedback.Duration);
}
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 4750cfc

Please sign in to comment.