本文主要是介绍Android Sensor的简单调用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
SensorManager sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);List<Sensor> allSensors = sm.getSensorList(Sensor.TYPE_ALL);for (Sensor s : allSensors) {String tempString = "\n" + " 设备名称:" + s.getName() + "\n" + " 设备版本:" + s.getVersion() + "\n" + " 供应商:" + s.getVendor() + "\n";switch (s.getType()) {case Sensor.TYPE_ACCELEROMETER:Log.e("--------",s.getType() + " 加速度传感器" + tempString);break;case Sensor.TYPE_GYROSCOPE:Log.e("--------",s.getType() + " 陀螺仪传感器" + tempString);break;case Sensor.TYPE_LIGHT:Log.e("--------",s.getType() + " 环境光线传感器" + tempString);break;case Sensor.TYPE_MAGNETIC_FIELD:Log.e("--------",s.getType() + " 电磁场传感器" + tempString);break;case Sensor.TYPE_ORIENTATION:Log.e("--------",s.getType() + " 方向传感器" + tempString);break;case Sensor.TYPE_PRESSURE:Log.e("--------",s.getType() + " 压力传感器" + tempString);break;case Sensor.TYPE_PROXIMITY:Log.e("--------",s.getType() + " 距离传感器" + tempString);break;case Sensor.TYPE_TEMPERATURE:Log.e("--------",s.getType() + " 温度传感器" + tempString);break;default:Log.e("--------",s.getType() + " 未知传感器" + tempString);break;}}
这里是调用各种传感器的方法,简单的记录一下。
public static final int TYPE_ALL = -1;
public static final int TYPE_ACCELEROMETER = 1;//加速度传感器
public static final int TYPE_MAGNETIC_FIELD = 2;//磁场传感器
public static final int TYPE_ORIENTATION = 3;//方向传感器
public static final int TYPE_GYROSCOPE = 4;//陀螺仪传感器
public static final int TYPE_LIGHT = 5;//光传感器
public static final int TYPE_PRESSURE = 6;//压力传感器
public static final int TYPE_TEMPERATURE = 7;//温度传感器
public static final int TYPE_PROXIMITY = 8;//距离传感器
public static final int TYPE_GRAVITY = 9;//重力传感器
public static final int TYPE_LINEAR_ACCELERATION = 10;//线性加速传感器
public static final int TYPE_ROTATION_VECTOR = 11;//旋转矢量传感器
public static final int TYPE_RELATIVE_HUMIDITY = 12;//相对湿度传感器
public static final int TYPE_AMBIENT_TEMPERATURE = 13;//温度传感器
public static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14;//磁场未校准传感器
public static final int TYPE_GAME_ROTATION_VECTOR = 15;//游戏矢量旋转传感器
public static final int TYPE_GYROSCOPE_UNCALIBRATED = 16;//陀螺仪未校准传感器
public static final int TYPE_SIGNIFICANT_MOTION = 17;//重要运动传感器
public static final int TYPE_STEP_DETECTOR = 18;//步进探测器传感器
public static final int TYPE_STEP_COUNTER = 19;//步数传感器
public static final int TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20;//地磁旋转矢量传感器
public static final int TYPE_HEART_RATE = 21;//心跳速度传感器
public static final int TYPE_POSE_6DOF = 28;//姿势传感器
public static final int TYPE_STATIONARY_DETECT = 29;//驻留检测传感器
public static final int TYPE_MOTION_DETECT = 30;//运动检测传感器
public static final int TYPE_HEART_BEAT = 31;//心跳传感器
public static final int TYPE_LOW_LATENCY_OFFBODY_DETECT = 34;//低潜伏离体传感器
public static final int TYPE_ACCELEROMETER_UNCALIBRATED = 35;//加速度计未校准传感器
public static final int TYPE_DEVICE_PRIVATE_BASE = 65536;//设备私有基础
这篇关于Android Sensor的简单调用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!