Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out if a device has a vibrator?

I have a device of which I don't know if it has a vibrator.

Is there a way to query for the availability of the vibrator?

like image 621
Octavian A. Damiean Avatar asked Jul 23 '11 15:07

Octavian A. Damiean


2 Answers

The Vibrator class does just that. It's hasVibrator() method returns a boolean indicating if vibrating is supported.

  1. Get an instance of the Vibrator class which is a system service.
  2. Query the Vibrator class using the hasVibrator() method.
String vs = Context.VIBRATOR_SERVICE;
Vibrator mVibrator = (Vibrator)getSystemService(vs);

boolean isVibrator = mVibrator.hasVibrator();
like image 57
Octavian A. Damiean Avatar answered Sep 22 '22 02:09

Octavian A. Damiean


This may help for API<11:

Context.getSystemService() returns a service object or null if no service.

if ( getSystemService(VIBRATOR_SERVICE) != null ) {
    //Vibrator exists
}
like image 28
t2tk Avatar answered Sep 23 '22 02:09

t2tk