# Vibration

## Get started <a href="#get-started" id="get-started"></a>

To access the Vibration functionality, the following platform specific setup is required.

### Android

The `VIBRATE` permission is required, and must be configured in the Android project. This permission can be added in the following ways:

* Add the assembly-based permission:

  Open the *Platforms/Android/MainApplication.cs* file and add the following assembly attributes after `using` directives:

  ```csharp
  [assembly: UsesPermission(Android.Manifest.Permission.Vibrate)]
  ```

{% hint style="warning" %}
This approach only applies to Wisej.NET Hybrid Local applications.
{% endhint %}

* \- or -
* Update the Android Manifest:

  Open the *Platforms/Android/AndroidManifest.xml* file and add the following in the `manifest` node:

  ```xml
  <uses-permission android:name="android.permission.VIBRATE" />
  ```

  \- or -
* Update the Android Manifest in the manifest editor:

  In Visual Studio double-click on the *Platforms/Android/AndroidManifest.xml* file to open the Android manifest editor. Then, under **Required permissions** check the **VIBRATE** permission. This will automatically update the *AndroidManifest.xml* file.

## Vibrate the device <a href="#vibrate-the-device" id="vibrate-the-device"></a>

The vibration functionality can be requested for a set amount of time or the default of 500 milliseconds. The following code example randomly vibrates the device between one and seven seconds.

```csharp
private void VibrateStartButton_Clicked(object sender, EventArgs e)
{
    int millisecondsToVibrate = Random.Shared.Next(1000, 7000);
    
    Device.Vibration.Vibrate(vibrationLength);
}

private void VibrateStopButton_Clicked(object sender, EventArgs e) =>
    Device.Vibration.Cancel();
```

## Platform differences <a href="#platform-differences" id="platform-differences"></a>

This section describes the platform-specific differences with the vibration API.

### iOS / Mac Catalyst

* Only vibrates when device is set to "Vibrate on ring".
* Always vibrates for 500 milliseconds.
* Not possible to cancel vibration.
