Q:

what is gyroscope and Accelerometer and how it use in Android

Everyone.. I am new on Android and i want to know about Accelerometer and Gyroscope.
How both are used in android app and how it works. I try a simple demo app for checking sensor found or not on Mobile Device. But it not Found.. Plz guide me on Both Gyroscope and Accelerometer.
This is my demo app class
public class MainActivity extends Activity {

private SensorManager mSensorManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    if(mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null)
    {
            Toast.makeText(getApplicationContext(), "Found", 9).show();
             // Sensor FOUND
    }
    else
    {
        Toast.makeText(getApplicationContext(), "NOt...Found", 9).show();
            //Sensor NOT FOUND
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}}

Thanx in advance..

A:

You can find this link useful in gyroscope for android
and for accelerometer start with this
public class yourActivity extends Activity implements SensorEventListener{
 private SensorManager sensorManager;
 double ax,ay,az;   // these are the acceleration in x,y and z axis
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
        sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
   }
   @Override
   public void onAccuracyChanged(Sensor arg0, int arg1) {
   }

   @Override
   public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
            ax=event.values[0];
                    ay=event.values[1];
                    az=event.values[2];
            }
   }
}

