AmyWuGo
AmyWuGo

Reputation: 2425

How can I know if the vibrator is working?

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.

Upvotes: 2

Views: 1193

Answers (2)

Krishnabhadra
Krishnabhadra

Reputation: 34285

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..

Upvotes: 1

gh.
gh.

Reputation: 339

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().

Upvotes: 0

Related Questions