java 将传感器管理器类型_方向更新为getOrientation()

wko9yo5t  于 2023-01-07  发布在  Java
关注(0)|答案(1)|浏览(91)

我有一个旧的cordova插件可以获得设备的方向。但是这个旧的方法不适用于一些新的设备

/**
 * Start listening for compass sensor.
 *
 * @return          status of listener
 */
public int start() {

    // If already starting or running, then just return
    if ((this.status == CompassListener.RUNNING) || (this.status == CompassListener.STARTING)) {
        return this.status;
    }

    // Get compass sensor from sensor manager
    @SuppressWarnings("deprecation")
    List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);

    // If found, then register as listener
    if (list != null && list.size() > 0) {
        this.mSensor = list.get(0);
        this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_NORMAL);
        this.lastAccessTime = System.currentTimeMillis();
        this.setStatus(CompassListener.STARTING);
    }

    // If error, then set status to error
    else {
        this.setStatus(CompassListener.ERROR_FAILED_TO_START);
    }

    return this.status;
}

 /**
 * Sensor listener event.
 *
 * @param SensorEvent event
 */
public void onSensorChanged(SensorEvent event) {

    // We only care about the orientation as far as it refers to Magnetic North
    float[] orientation = event.values;

    // Save heading
    this.timeStamp = System.currentTimeMillis();
    this.orientation = orientation;
    this.setStatus(CompassListener.RUNNING);

    // If heading hasn't been read for TIMEOUT time, then turn off compass sensor to save power
    if ((this.timeStamp - this.lastAccessTime) > this.TIMEOUT) {
        this.stop();
    }
}

我的问题是如何将其更新到新的方式sensor.getOrientation()?
任何帮助都很好
谢啦,谢啦

zxlwwiss

zxlwwiss1#

我认为这张PR应该有你正在寻找的变化(它不是我的):https://github.com/apache/cordova-plugin-device-orientation/pull/78在问题中,有人还说他们创建了一个解决问题的分叉。

相关问题