How can I request the vibrate permission?

73,149

Solution 1

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

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

Share:
73,149
Hardik Gajjar
Author by

Hardik Gajjar

Updated on March 09, 2020

Comments

  • Hardik Gajjar
    Hardik Gajjar about 4 years

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

  • codepleb
    codepleb over 10 years
    hahaha, you wrote "vibrator" :'D Seriously, thanks for this answer! :)
  • Peter Arandorenko
    Peter Arandorenko about 10 years
    To be really clear... add it within your <manifest ...> tag! Do not add it to any other tag!
  • cutiko
    cutiko almost 8 years
    I have being looking for the permissions list for a while thanks
  • Arun Prasad
    Arun Prasad almost 4 years
    How about iOS, i meant iPhone ?
  • JJ86
    JJ86 about 2 years
    If you can, update your answer with this: val vibrationEffect = VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE) vibrator.vibrate(vibrationEffect). This is for Android O and newer versions.