//获取TYPE变量名称 String getSensorStringType(int typeCode){ Field[] _fields=Sensor.class.getFields(); for (Field _field : _fields) { try { if(_field.getGenericType().equals(int.class) &&typeCode==_field.getInt(null)){ return _field.getName(); } } catch (IllegalAccessException e) { e.printStackTrace(); } } return "Not Find Sensor Name TypeCode="+typeCode; }
// 获取传感器管理者 SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); //获取手机全部的传感器 List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); //迭代输出传感器TYPE变量名 for (Sensor sensor : sensors) { Log.i("Sensor", getSensorStringType(sensor.getType()) ); }