How can I find out if a device has a vibrator?
The Vibrator
class does just that. It's hasVibrator()
method returns a boolean indicating if vibrating is supported.
- Get an instance of the Vibrator class which is a system service.
- Query the Vibrator class using the
hasVibrator()
method.
String vs = Context.VIBRATOR_SERVICE;
Vibrator mVibrator = (Vibrator)getSystemService(vs);
boolean isVibrator = mVibrator.hasVibrator();
This may help for API<11:
Context.getSystemService()
returns a service object or null
if no service.
if ( getSystemService(VIBRATOR_SERVICE) != null ) {
//Vibrator exists
}