2

Is there any event which is fired when the android phone is vibrating so I can subscribe my event handler to it?

Thank you for your time.

Tarik
  • 79,711
  • 83
  • 236
  • 349
AmyWuGo
  • 2,315
  • 4
  • 22
  • 26

2 Answers2

1

You can use Context.getSystemService() to get a Vibrator object. Using that object you can identify whether phone has a vibrator.

Vibrator vibrator  = context.getSystemService(Context.VIBRATOR_SERVICE);

to identfiy whether phone has a vibrator, use hasVibrator()

 vibrator.hasVibrator()

You can start and stop vibration using

vibrate.vibrate(long milliseconds);
vibrate.cancel();

EDIT: After seeing op's comment..

I don't think you will get notification when phone starts vibrating AFAIK. (Happy if someone clears me wrong).. You can find out whether phone is in vibration mode or silent mode or normal mode (See this).. But vibration mode doesn't mean phone is vibrating right now..

Community
  • 1
  • 1
Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
0

getVibrateSetting(int vibrateType) BUT: This method is deprecated. Applications should maintain their own vibrate policy based on current ringer mode that can be queried via getRingerMode().

gh.
  • 339
  • 1
  • 3
  • 20
  • I don't want to know the OS setting or the OS status. – AmyWuGo Sep 07 '12 at 03:44
  • Your question states: "Could I get the status from the OS service?" and your comment states: "I don't want to know the OS setting or the OS status." Make up my mind what you want friend. – gh. Sep 07 '12 at 03:48