标签:
1.
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //得到SensorManager对象 sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); sensorButton = (Button)findViewById(R.id.sensorButton); sensorButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //通过调用getSensorList方法,得到当前手机当中所有的传感器 List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensors) { System.out.println(sensor.getName()); } //通过调用getDefaultSensor方法,获取某一个类型的默认传感器 Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); } }); }
ANDROID_MARS学习笔记_S05_001_用SensorManager获取传感器
标签:
原文地址:http://www.cnblogs.com/shamgod/p/5207231.html