Android examples for Hardware:Sensor
Return string value for the sensor unit
//package com.java2s; import android.hardware.Sensor; public class Main { /**/*w w w .j av a 2 s .c o m*/ * Return string value for the sensor unit * * @param sensor the sensor type * @return String value for the sensor unit */ @SuppressWarnings("deprecation") static public String getSensorUnitString(Sensor sensor) { String sensorUnitString; switch (sensor.getType()) { case Sensor.TYPE_ACCELEROMETER: sensorUnitString = "Acceleration(m/sec^2)"; break; case Sensor.TYPE_GYROSCOPE: sensorUnitString = "Angular Velocity(rad/sec)"; break; case Sensor.TYPE_LIGHT: sensorUnitString = "Brightness(SI lux)"; break; case Sensor.TYPE_MAGNETIC_FIELD: sensorUnitString = "Magnetic-field(uT)"; break; case Sensor.TYPE_ORIENTATION: sensorUnitString = "Angle(?)"; break; case Sensor.TYPE_PRESSURE: sensorUnitString = "Pressure(hPa)"; break; case Sensor.TYPE_PROXIMITY: sensorUnitString = "Distance(cm)"; break; case Sensor.TYPE_TEMPERATURE: sensorUnitString = "Temperature(?)"; break; case Sensor.TYPE_LINEAR_ACCELERATION: sensorUnitString = "Linear-Acceleration(m/sec^2)"; break; case Sensor.TYPE_GRAVITY: sensorUnitString = "Gravity(m/sec^2)"; break; case Sensor.TYPE_ROTATION_VECTOR: sensorUnitString = "Rotation Vector"; break; default: sensorUnitString = sensor.getName(); break; } return sensorUnitString; } }