Java tutorial
//package com.java2s; import android.hardware.Sensor; import android.hardware.SensorEventListener; import android.hardware.SensorManager; public class Main { private static SensorManager sensorManager; public static boolean startSensor(int sensorType, SensorEventListener listener) { Sensor sensor = getSensor(sensorType); return sensor != null && sensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_NORMAL); } public static Sensor getSensor(int type) { return sensorManager.getDefaultSensor(type); } }