• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps access compas sensor

step 1, get an instance of SensorManager:
Code:
SensorManager manager = (SensorManager)context.getSystemService(SENSOR_SERVICE);
step 2, get a list of sensors, in this case the TYPE_MAGNETIC_FIELD sensor:
Code:
ArrayList<Sensor> list = manager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
step 3, check if there are any sensors in the list. If there aren't, the phone doesn't have a compas sensor.

step 4, register a SensorEventListener with the SensorManager (see the documentation for this).

step 5, experiment. (cuz I don't know what to do next since I haven't used the sensors yet).
 
Back
Top Bottom