private SensorManager mSensorManager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the texts fields of the layout and set to invisible
TextView sensorCountText =
(TextView) findViewById(R.id.sensorCountText);
TextView sensorNamesText =
(TextView) findViewById(R.id.sensorNamesText);
// Get the SensorManager
mSensorManager =
(SensorManager) getSystemService(Context.SENSOR_SERVICE);
// get a list of available sensors
List<Sensor> sensors =
mSensorManager.getSensorList(Sensor.TYPE_ALL);
// Print how may Sensors there are
sensorCountText.setText(sensors.size() +" sensors available.");
// Print the name of each Sensor
StringBuilder out = new StringBuilder();
for(Sensor s : sensors){
out.append(s.getName()).append("\n");
}
sensorNamesText.setText(out.toString());
}
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎