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.

  1. 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 declare ListView.ListAdapter, and SensorManager, along with the list of Sensor Objects to populate the list:
     public class SensorListActivity extends Activity implements OnItemClickListener{ private SensorManager mSensorManager; private ListView mSensorListView; ...

Get Android Sensor Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.