Adding Haptic Feedback to your MAUI app [part 1: MAUI]

7 years ago, I wrote a post about Haptic feedback in Xamarin. Now that Xamarin is gone, it is time to refresh that. This is part of a series of posts dedicated to Haptic Feedback in the .NET multi-platform realm. This post will cover the usage of the MAUI shared API (HapticFeedback).

Adding Haptic Feedback to your MAUI app [part 1: MAUI]
Photo by Meagan Carsience / Unsplash

This is part of a series of posts dedicated to Haptic Feedback in the .NET multi-platform realm.

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"

⚠️
Unfortunately, there is no API to detect or override this setting programmatically.

More articles to come, covering the platforms (Android, iOS and Windows) in-depth.

Code sample

Check out my MAUI playground:

GitHub - framinosona/Maui-Developer-Sample at blog/HapticFeedback1
This is my playground, I try to make things as clean as possible so that I can reuse them. - GitHub - framinosona/Maui-Developer-Sample at blog/HapticFeedback1

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 ...

We will see on how to unlock this in the next post.

Stay tuned 🙂