doc/articles/features/windows-devices-haptics.md
[!TIP] This article covers Uno-specific information for the
Windows.Devices.Hapticsnamespace. For a full description of the feature and instructions on using it, see Windows.Devices.Haptics Namespace.
Windows.Devices.Haptics namespace provides classes for accessing and managing vibration devices and haptic feedback.VibrationDevice classThe GetDefaultAsync method is implemented on all platforms and returns null for the unsupported platforms (Skia Desktop).
For Android, there is one permission you must configure before using this API in your project. To do that, add the following to AndroidManifest.xml:
<uses-permission android:name="android.permission.VIBRATE" />
For Tizen, the http://tizen.org/privilege/haptic privilege needs to be declared in tizen-manifest.xml file.
SimpleHapticsControllerThe SupportedFeedback property returns the list of supported feedback types for the given platform. In most cases this includes Click and Press.
The following code snippet illustrates the usage of VibrationDevice and SimpleHapticsController:
var result = await VibrationDevice.RequestAccessAsync();
if (result == VibrationAccessStatus.Allowed)
{
var vibrationDevice = await VibrationDevice.GetDefaultAsync();
if (vibrationDevice != null)
{
var simpleHapticsController = vibrationDevice.SimpleHapticsController;
var feedbackType = simpleHapticsController.SupportedFeedback.FirstOrDefault(
feedback => feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Press);
if (feedbackType != null)
{
simpleHapticsController.SendHapticFeedback(feedbackType);
}
}
}