Friday, February 18, 2011

Get the list of available sensors, SensorManager.getSensorList()

The class android.hardware.SensorManager provide a method getSensorList(). Use this method to get the list of available sensors of a certain type, or use Sensor.TYPE_ALL to get all the sensors.

Get the list of available sensors, SensorManager.getSensorList()

package com.exercise.AndroidSensorList;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class AndroidSensorList extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
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++){

setListAdapter(new ArrayAdapter<String>(this,

Download the files.

Related Article:
- Detect rotation around X, Y & Z axis, using SensorManager and SensorEventListener
- Detect Android Accelerometer sensor changed

No comments: