java - 如何通过移动手机进行更改

标签 java android

我想开发一款像单挑这样的游戏! 我需要的是,当用户向下移动手机时,会调用一些函数,如何编写代码?

最佳答案

您可以使用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/

相关文章:

java - 如何检索保存为 blob 的图像

java - Kotlin协程vs CompletableFuture

java - 为什么 JPA Transient 注解在 Target 中有方法?

android - 每页有 30 个按钮的 DirectionalViewPager

android - OOM(内存不足异常)如何在android中发生?

java - 如何用java解方程?

java - 如何在Spring Kafka中动态创建多个消费者

Android ICS Webview textarea 打字慢

java - Libgdx - 纹理未显示在屏幕更改上

java - Odroid N2 "getGpioList()"返回空数组,无法访问 gpio 端口