Adding Haptic Feedback / Vibrations to your MAUI app
The basics
By default, the goal of MAUI is to simplify the developer's work by providing an ultra-simple API. It can't get simpler than this:
// Simple click
HapticFeedback.Default.Perform(HapticFeedbackType.Click);
// Longer click
HapticFeedback.Default.Perform(HapticFeedbackType.LongPress);
Platform considerations
Most of the time, platforms allow the user to disable Haptic Feedback, here are where to find these settings:
🤖 Android
In Android, there is a setting often found under Settings > Sound & vibration > Vibration & haptics.
In addition, you'll need to add the permission for VIBRATE in your AndroidManifest.xml :
<uses-permission android:name="android.permission.VIBRATE" />
🍏 iOS
In iOS you'll need to navigate to Settings > Sounds & Haptics, and enable "System Haptics"
More articles to come, covering the platforms (Android, iOS and Windows) in-depth.
Code sample
Here is a simple Bindable singleton, for easy demonstration.
namespace Maui_Developer_Sample.Pages.Vibrations.BindableHapticFeedback;
public class BindableHapticFeedbackSimple : BindableObject
{
#region Singleton
private readonly static Lazy<BindableHapticFeedbackSimple> LazyInstance = new Lazy<BindableHapticFeedbackSimple>(() => new BindableHapticFeedbackSimple());
public static BindableHapticFeedbackSimple Instance => LazyInstance.Value;
#endregion
private BindableHapticFeedbackSimple()
{
VibrateClickCommand = new Command(VibrateClick);
VibrateLongPressCommand = new Command(VibrateLongPress);
}
private void VibrateClick() => HapticFeedback.Default.Perform(HapticFeedbackType.Click);
private void VibrateLongPress() => HapticFeedback.Default.Perform(HapticFeedbackType.LongPress);
public Command VibrateClickCommand { get; }
public Command VibrateLongPressCommand { get; }
}
Check out my MAUI playground for a full sample:
Results
You should feel a very faint vibration, even the "LongPress" is not strong. It's normal. These are meant to add a little extra to your User Experience, not to be used as a massage gun ...
For advanced patterns like waveform control, intensity, or cross-platform abstraction, native implementations will be necessary. I’ll cover that in a future post.
Stay tuned 🙂