@Override public void onClick(View arg0) { // TODO Auto-generated method stub //声明可变字符串 StringBuffer sb = new StringBuffer(); //获取手机全部的传感器 List sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); //迭代输出获得上的传感器 for (Sensor sensor : sensors) { //System.out.println(sensor.getName().toString()); sb.append(sensor.getName().toString()); sb.append("\n"); Log.i("Sensor", sensor.getName().toString()); } //给文本控件赋值 v.setText(sb.toString()); } }); } public SensorTest() { // TODO Auto-generated constructor stub angle[0] = 0; angle[1] = 0; angle[2] = 0; timestamp = 0; }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_sensor_test, menu); return true; } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); sensorManager.unregisterListener(this); // 解除监听器注册 } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); sensorManager.registerListener(this, gyroSensor, SensorManager.SENSOR_DELAY_NORMAL); //为传感器注册监听器 } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { // TODO Auto-generated method stub
} @Override public void onSensorChanged(SensorEvent event) { // TODO Auto-generated method stub // if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) // { // return; // }