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

后端 未结 4 1106
臣服心动
臣服心动 2021-01-03 17:58

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?

4条回答
  •  长发绾君心
    2021-01-03 18:26

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

提交回复
热议问题