2
有没有办法检测“手腕倾斜屏幕唤醒”行动手表表面处于活动状态?我希望我的表盘能够检测到此动作,以便通过再次倾斜手表来延迟屏幕超时(作为示例)。Android Wear检测手表在脸上倾斜/ app
有没有办法检测“手腕倾斜屏幕唤醒”行动手表表面处于活动状态?我希望我的表盘能够检测到此动作,以便通过再次倾斜手表来延迟屏幕超时(作为示例)。Android Wear检测手表在脸上倾斜/ app
大多数基于Android的设备都具有内置传感器,可以测量运动,方向和各种环境条件。这些传感器能够以高精度和准确度提供原始数据。您可以使用运动传感器来检测诸如倾斜,摇晃,旋转或摆动。
有三个支撑大类传感器:
这里的用于感测重力和加速度计的样品的代码:
private SensorManager mSensorManager;
private Sensor mSensor;
...
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensor = null;
if (mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY) != null){
List<Sensor> gravSensors = mSensorManager.getSensorList(Sensor.TYPE_GRAVITY);
for(int i=0; i<gravSensors.size(); i++) {
if ((gravSensors.get(i).getVendor().contains("Google Inc.")) &&
(gravSensors.get(i).getVersion() == 3)){
// Use the version 3 gravity sensor.
mSensor = gravSensors.get(i);
}
}
}
if (mSensor == null){
// Use the accelerometer.
if (mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null){
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
else{
// Sorry, there are no accelerometers on your device.
// You can't play this game.
}
}
有关传感器管理器的更多信息,请查看:https://developer.android.com/guide/topics/sensors/sensors_overview.html