Question

I am a new to Android development and I would like to create an application which shows the list of sensors on my Android device.

I tried to find this but without the success.

Can you please help me.

Here is the solution how to do this:

///////////////  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());
}
Was it helpful?

Solution

Try this code:

SensorManager mgr = (SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor> sensors = mgr.getSensorList(Sensor.TYPE_ALL);
for (Sensor sensor : sensors) {
    Log.d("Sensors", "" + sensor.getName());
}

my output is:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top