我想开发一款像单挑这样的游戏! 我需要的是,当用户向下移动手机时,会调用一些函数,如何编写代码?
最佳答案
您可以使用RxSensor,它是 Android 传感器的响应式(Reactive)包装器。可以在这里找到https://android-arsenal.com/details/1/3350
<小时/>Android 在 Here 有一组传感器和 Motion Sensor Documentation 。
<小时/>RxSensor 的示例用法和 Android Motion 文档
以传感器 TYPE_ACCELEROMETER
RxSensor rxSensor = new RxSensor(this);
//Note where i have put TYPE_ACCELEROMETER
rxSensor.observe(Sensor.TYPE_ACCELEROMETER, SensorManager.SENSOR_DELAY_NORMAL)
.subscribe(new Subscriber<RxSensorEvent>() {
@Override
public void onCompleted() { }
@Override
public void onError(Throwable e) { }
@Override
public void onNext(RxSensorEvent sensorEvent) {
Log.d("RxSensor", "event: " + sensorEvent.toString());
}
});
TYPE_ACCELEROMETER
Acceleration force along the x axis (including gravity).
TYPE_ACCELEROMETER_UNCALIBRATED
Measured acceleration along the X axis without any bias compensation and many more types if you look at the documentation
关于java - 如何通过移动手机进行更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57140297/