Time for action – listing the available sensors on a device
There are multiple sensors available on a device. In this section, we will learn how to get a list of all the available sensors. We will be populating the names of the available sensors in a list and will be displaying it on the screen using ListView
.
The following code block shows the declarations required by the activity. We don't need the
SensorEventListener
interface, as we will not be dealing with the values of the sensor. We declareListView
.ListAdapter
, andSensorManager
, along with the list ofSensor
Objects to populate the list:public class SensorListActivity extends Activity implements OnItemClickListener{ private SensorManager mSensorManager; private ListView mSensorListView; private ListAdapter mListAdapter; private List<Sensor> mSensorsList;
In the
onCreate()
method, we instantiate ourSensorManager
,ListView
, andListAdaptor...