access compas sensor

Last Updated:

  1. ecross

    ecross New Member

    hello all,

  2. id0001

    id0001 Well-Known Member

    step 1, get an instance of SensorManager:
    Code (Text):
    1. SensorManager manager = (SensorManager)context.getSystemService(SENSOR_SERVICE);
    step 2, get a list of sensors, in this case the TYPE_MAGNETIC_FIELD sensor:
    Code (Text):
    1. 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).

Share This Page