Android: How to use SensorManager.getAltitude(float p0, float p)?

前端 未结 2 1409
悲哀的现实
悲哀的现实 2020-12-17 05:30

I found an alternative way to obtain altitude by using SensorManager but it requires two paramaters.

public static float  getAltitude  (float p0, float p)

C         


        
2条回答
  •  囚心锁ツ
    2020-12-17 06:03

    try

    List sensors = sensorManager.getSensorList(Sensor.TYPE_PRESSURE);
    if(sensors.size() > 0) {
    
    
      sensor = sensors.get(0);
      mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
    
    }
    

     public void onAccuracyChanged(Sensor sensor, int accuracy) {
     }
    
     public void onSensorChanged(SensorEvent event) {
        presure = event.values[0];
     }
    

    float altitude = getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, presure);
    

提交回复
热议问题