3

in Some cases in your app you just wanna the phone to vibrate if a certain button in your app has been clicked , in my case there is a search mode that switching to and from this mode will make the phone vibrate and also this would happen if the "back" key is pressed , and if the user has enabled the vibrate for software keys in setting then there will be 2 quick vibrates and its not cool , I was wondering if there is any way to detect this cause I cant simply disable it cause in some phones it may be disabled or the key is software so there wont be any vibrate at all thanks

Mahan
  • 147
  • 1
  • 3
  • 14

2 Answers2

1

Unfortunately there is no listener for event handling vibrations. see this question

you cant help with it even accelerometer or shake listener. It would be too weak to detect. See documentation if it helps.

Community
  • 1
  • 1
Istiak Morsalin
  • 10,621
  • 9
  • 33
  • 65
  • unfortunately these didn't help , just played with the method cancel() on vibrator object and couldn't solve it , also tried detecting it by shake listener and again no results , and the method on the other question you mentioned just detect the vibrates that are created by my app and so I guess there isn't any way to do this – Mahan Feb 22 '17 at 07:59
  • Yes, there is not a way actually. if found, keep me posted – Istiak Morsalin Feb 22 '17 at 08:07
-1

Use bellow code for vibration :

Vibrator v1 = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
v1.vibrate(500);

Add permission in android manifest :

<uses-permission android:name="android.permission.VIBRATE"/> 
Istiak Morsalin
  • 10,621
  • 9
  • 33
  • 65
Patel Jaimin
  • 231
  • 1
  • 11