10

I know about the Vibrate class and how to use it, but where can I get the system default vibration pattern to use? Or is there some kind of intent I can launch to get the system to vibrate its default vibration?

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
Mohamed Hafez
  • 8,621
  • 7
  • 41
  • 49
  • Is this for use with a notification, or just in general? – Paul Burke Sep 23 '13 at 21:40
  • 2
    oh i know how to do it for notifications, I'm trying to create a VibratorPreference analagous to RingtonePreference, and i want to 'play' the vibration on each selection – Mohamed Hafez Sep 24 '13 at 01:08
  • I did just gave a try. Looks like 50 is close to my Acer tab under API 19 where 20 is approx what my Galaxy 5 does, under API 21... I can't find any predefined pattern in the API though. – Shlublu Feb 23 '16 at 19:55

2 Answers2

7

Create a method that reproduce the default vibration and call it on every selection.

import android.os.Vibrator;

private void vibrate(){
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(1000);
    }

permission required in AndroidManifest.xml file:

<uses-permission android:name="android.permission.VIBRATE"/>
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
  • 11
    but 1000 is not the default value for vibration right ? Is there any way, by which we can get android's default vibration pattern ? – Ravi Bhojani Jul 06 '15 at 09:36
  • 1
    I've been testing some different values and I think any value between 20 and 50 ms can make it, depending on what you need. To me 50 ms feels like the buttons on my phone, and 20 ms is more like an item selection inside an app. – juanmi Sep 16 '15 at 21:51
  • @JuanMiguel Just gave a try. Looks like 50 is close to my Acer tab under API 19 where 20 is approx what my Galaxy 5 does, under API 21... I can't find any predefined pattern in the API though. – Shlublu Feb 23 '16 at 19:54
  • I've looked in the latinime (google keyboard) and they have a table for finding the values :( – Warpzit Mar 07 '16 at 14:32
2

See View.performHapticFeedback.

mhsmith
  • 6,675
  • 3
  • 41
  • 58