How to use Accelerometer/ Sensor Change Android

ဖုန္းကုိ ကုိင္လွဳပ္လုိက္တဲ့အခ်ိန္မွာ ေျပာင္းလဲလာတဲ့ တန္ဖုိးေတြေပၚမူတည္ျပီး သင့္ App ကုိတည္ေဆာက္ခ်င္တယ္ ဆုိရင္ ေတာ့ ေအာက္ ပါ Code ေတြကုိ သင္သုံးရပါမယ္ ..



import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
public class MainActivity extends Activity implements SensorEventListener {
    int b;
    int a;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SensorManager mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
        Sensor mAccelerometer =mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        mSensorManager.registerListener(this, mAccelerometer,SensorManager.SENSOR_DELAY_FASTEST);
        setContentView(R.layout.activity_main);
        }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    @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 x = event.values[0];
    float y = event.values[1];
    float z = event.values[2];
    //    ဒီ Method မွာ ကို္ယ္ေရးခ်င္တာေရးပါ .. မိမိ တုိ ့လုိခ်င္တဲ့ Sensor ကုိ စဥ္းစားျပီး အသုံးခ်ပါ ..
    }
}
Download Code Attachment