How can I request the vibrate permission?

AndroidAndroid Vibration

Android Problem Overview


How can I request the vibrate permission in my Android application?

Android Solutions


Solution 1 - Android

Here is the link to the reference

Add this to your manifest, as a direct child of the manifest element:

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

This is how you let the phone Vibrate thru code:

// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

// Vibrate for 300 milliseconds
v.vibrate(300);

For a more creative pattern try the star wars theme =D

v.vibrate(new long[]{0, 500, 110, 500, 110, 450, 110, 200, 110, 170, 40, 450, 110, 200, 110, 170, 40, 500}, -1);

Solution 2 - Android

Add the following in your AndroidManifest.xml:

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

More info on AndroidManifest permissions here

More info on list of permission here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHardik GajjarView Question on Stackoverflow
Solution 1 - AndroidMark MooibroekView Answer on Stackoverflow
Solution 2 - AndroidcchenesonView Answer on Stackoverflow