How to detect the motion sensor in the broadcast receiver?


I had written one receiver to detect device motion is changed or not like this in Manifest.xml

 <receiver android:name="com.hanuman.sensor.receiver.SensorReceiver" >
                android:exported="false" >
                <action android:name="android.intent.action.USER_PRESENT" />

and inside receiver onReceive() method code is:

String action = intent.getAction();
        if (action.equals(Intent.ACTION_USER_PRESENT)) {
            System.out.println("User is present");
            Intent s = new Intent(context, MainActivity.class);
        } else {
            System.out.println("User is not present");

finally my question is, is not detecting the sensor when it is motioned, it is detecting when my device in unlocked then it is calling my MainActivity, but i want to detect when my device motion is changed then i want to detect in receiver. How can i do that?.

Get object of SensorManager like below-

SensorManager sensorMan = (SensorManager)getSystemService(SENSOR_SERVICE);

Sensor sensor = sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

Register listener to listen changes in motion sensor-

sensorMan.registerListener(context, sensor,

Then override onSensorChanged() method to detect changes-

public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
    //do some stuff
    //do some other code for other Sensor type