我有一个装置,我不知道它有没有振动器。
有没有办法查询可控震源的可用性?
发布于 2011-07-24 00:03:19
Vibrator
类就是这样做的。它的hasVibrator()
方法返回一个布尔值,表示是否支持振动。
hasVibrator()
方法查询可控震源类。String vs = Context.VIBRATOR_SERVICE;
Vibrator mVibrator = (Vibrator)getSystemService(vs);
boolean isVibrator = mVibrator.hasVibrator();
发布于 2013-01-27 21:23:01
这可能会对API<11有所帮助:
Context.getSystemService()
返回服务对象,如果没有服务,则返回null
。
if ( getSystemService(VIBRATOR_SERVICE) != null ) {
//Vibrator exists
}
发布于 2012-02-20 09:48:06
在使用hasVibrator()之前,您需要(至少)支持Android3.0 (11 HoneyComb)。
奇怪的是,你可以在任何/所有版本上使用vibrate()本身。
所以真正的问题是: v1 - v10如何检测设备是否有可控震源?(或者,如果您尝试在没有振动器的情况下振动设备,会不会发生什么不好的事情?)
https://stackoverflow.com/questions/6801574
复制相似问题