title: Android Sensor Data
body: <p>I want to collecting some data from my accelerometer sensor in my android smartphone. I have try some ways, the best way is using service class and call it in activity class, but this method just give me three axes data of that time.
  My intention is to collect data from second to second, i mean everytime the data changed, it will be recorded in log file, so i can get some data appended second from second.</p>
  
  <p>Anyone can help me?, im so glad for the help.
  Thank you very much for the advance.</p>
  
  <p>i have already implement it  here is my activity code </p>
  
  <pre><code>package trying.gapickerwithservice;
  import android.app.Activity;
  import android.content.Context;
  import android.hardware.Sensor;
  import android.hardware.SensorEvent;
  import android.hardware.SensorEventListener;
  import android.hardware.SensorManager;
  import android.os.Bundle;
  import android.renderscript.Type;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.EditText;
  public class GAPickerWithService extends Activity implements SensorEventListener
  {
      Sensor mySens;
      String giro;
      EditText VALUE;
      SensorManager sensorManager;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.gapickerwserv);
          sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
          Sensor mySens = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
          sensorManager.registerListener(this, mySens, SensorManager.SENSOR_DELAY_NORMAL);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.gapicker_with, menu);
          return true;    
      }   
      @Override
      public void onAccuracyChanged(Sensor arg0, int arg1) {
          // TODO Auto-generated method stub
  
      }   
      @Override
      public void onSensorChanged(SensorEvent event) {
          VALUE = (EditText) findViewById(R.id.value);
          float Roll = event.values[2];
          float Pitch = event.values[1];
          float Yaw = event.values[0];
          giro = Float.toString(Pitch)+Float.toString(Roll)+Float.toString(Yaw);
          VALUE.setText(giro);
          // TODO Auto-generated method stub  
      }       
      protected void onResume(){
          super.onResume();
          sensorManager.registerListener(this, mySens, SensorManager.SENSOR_DELAY_NORMAL);
      }
  
      protected void onPause(){
          super.onPause();
          sensorManager.unregisterListener(this);
      }
      }
  </code></pre>
  
  <p>and this is my service code</p>
  
  <pre><code>package trying.gapickerwithservice;
  import android.app.Service;
  import android.content.Intent;
  import android.hardware.Sensor;
  import android.hardware.SensorEvent;
  import android.hardware.SensorEventListener;
  import android.hardware.SensorManager;
  import android.os.IBinder;
  import android.util.Log;
  import android.widget.EditText;
  
  public class GAPickerGyroService extends Service implements SensorEventListener {
  Sensor mySens;
  static final String TAG = "GAPickerGyroService";
  private SensorManager mySensMan;
  String giro;
  @Override
  public IBinder onBind(Intent intent) {
      // TODO Auto-generated method stub
      return null;
  }
  public void onCreate ()
  {
      mySensMan = (SensorManager) getSystemService(SENSOR_SERVICE);
      mySens = mySensMan.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
      mySensMan.registerListener(this, mySens, SensorManager.SENSOR_DELAY_NORMAL);
  }
  @Override
  public void onAccuracyChanged(Sensor arg0, int arg1) {
      // TODO Auto-generated method stub      
  }
  @Override
  public void onSensorChanged(SensorEvent event) {
      // TODO Auto-generated method stub
  
      float Roll = event.values[2];
      float Pitch = event.values[1];
      float Yaw = event.values[0];
      giro = Float.toString(Pitch)+Float.toString(Roll)+Float.toString(Yaw);
      Log.d(TAG, giro);
  }       
  }
  </code></pre>