更新:他们更新了 Lollipop 中的 getDefaultSensor 方法,现在有所不同:
public Sensor getDefaultSensor(int type) {
// TODO: need to be smarter, for now, just return the 1st sensor
List<Sensor> l = getSensorList(type);
boolean wakeUpSensor = false;
// For the following sensor types, return a wake-up sensor. These types are by default
// defined as wake-up sensors. For the rest of the SDK defined sensor types return a
// non_wake-up version.
if (type == Sensor.TYPE_PROXIMITY || type == Sensor.TYPE_SIGNIFICANT_MOTION ||
type == Sensor.TYPE_TILT_DETECTOR || type == Sensor.TYPE_WAKE_GESTURE ||
type == Sensor.TYPE_GLANCE_GESTURE || type == Sensor.TYPE_PICK_UP_GESTURE) {
wakeUpSensor = true;
}
for (Sensor sensor : l) {
if (sensor.isWakeUpSensor() == wakeUpSensor) return sensor;
}
return null;
}
因此,如果指定类型有多个传感器可用,getDefaultSensor 将返回非唤醒版本(除非默认类型是上述 6 个实际定义为唤醒传感器的类型之一)
顺便说一句,Sensor.TYPE_TILT_DETECTOR、Sensor.TYPE_WAKE_GESTURE、Sensor.TYPE_GLANCE_GESTURE 和 Sensor.TYPE_PICK_UP_GESTURE 在 SDK 中是隐藏的,因为它们仅用于系统 UI。Sensor.java 源代码中提供了有关它们的更多详细信息