Is there a way to detect the "wrist tilt to wake screen" action WHILE the watch face is active? I would like my watch face to detect this action so that it delays the screen timeout by tilting the watch again (as an example).
Asked
Active
Viewed 548 times
1 Answers
1
Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. These sensors are capable of providing raw data with high precision and accuracy. You can use Motion sensors to detect such as tilt, shake, rotatio or swing.
There are three support broad categories of sensors:
- Motion sensors
- Environmental sensors
- Position sensors
Here's a sample code for sensing gravity and Accelerometer:
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.
}
}
For more information regarding sensormanager, check this: https://developer.android.com/guide/topics/sensors/sensors_overview.html

Android Enthusiast
- 4,826
- 2
- 15
- 30