public class Activity extends ActionBarActivity implements SensorEventListener{ SensorManager sensorManager; EditText et_sensor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); et_sensor = (EditText) findViewById(R.id.et_sensor); sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE); } @Override protected void onResume() { super.onResume(); sensorManager.registerListener(this,sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME); } @Override protected void onStop() { sensorManager.unregisterListener(this); super.onStop(); } @Override public void onSensorChanged(SensorEvent event) { float[] values = event.values; StringBuilder sb = new StringBuilder(); sb.append("rate of x axis : "+values[0]); sb.append("\n rate of y axis : " + values[1]); sb.append("\n rate of z axis : " + values[2]); et_sensor.setText(sb.toString()); } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } }