我是Android开发新手,我想创建一个显示Android设备上传感器列表的应用程序。
我试图找到这个,但没有成功。
你能帮我吗?以下是解决方法:
/////////////// List of Sensors //////////////////////////////
listeCapteurs = (ListView) findViewById(R.id.ListView01);
SensorManager sensorManager=
(SensorManager)getSystemService(Context.SENSOR_SERVICE);
List<Sensor> listSensor=
sensorManager.getSensorList(Sensor.TYPE_ALL);
List<String> listSensorType = new ArrayList<String>();
for(int i=0; i<listSensor.size(); i++)
{
listSensorType.add(listSensor.get(listSensor.size()-1-i).getName());
}
答案 0 :(得分:14)
试试这段代码:
SensorManager mgr = (SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor> sensors = mgr.getSensorList(Sensor.TYPE_ALL);
for (Sensor sensor : sensors) {
Log.d("Sensors", "" + sensor.getName());
}
我的输出是:
10-28 21:34:03.224: D/Sensors(27760): BMA150 3-axis Accelerometer
10-28 21:34:03.224: D/Sensors(27760): AK8973 3-axis Magnetic field sensor
10-28 21:34:03.224: D/Sensors(27760): AK8973 Orientation sensor
10-28 21:34:03.224: D/Sensors(27760): CM3602 Proximity sensor
10-28 21:34:03.224: D/Sensors(27760): CM3602 Light sensor
10-28 21:34:03.224: D/Sensors(27760): Gravity Sensor
10-28 21:34:03.224: D/Sensors(27760): Linear Acceleration Sensor
10-28 21:34:03.224: D/Sensors(27760): Rotation Vector Sensor