当运动传感器检测到电话移动时,有没有办法打开屏幕? 提前谢谢。
答案 0 :(得分:2)
考虑这样的事情
//implement SensorEventListener
public class SensorActivity extends Activity, implements SensorEventListener {
......
SensorManager sensorMan = (SensorManager)getSystemService(SENSOR_SERVICE);
Sensor sensor = sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorMan.registerListener(context, sensor,
SensorManager.SENSOR_DELAY_UI);
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
}
//Or some other sensor.
}
文档here
中有更多信息答案 1 :(得分:2)
这是为了打开屏幕,
public void turnOnScreen() {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
if (!powerManager.isScreenOn()) {
PowerManager.WakeLock screenWakeLock = powerManager.newWakeLock( PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "tag");
screenWakeLock.acquire();
screenWakeLock.release();
}
}