Code example for SensorManager

Methods: getDefaultSensorregisterListenerunregisterListener

0
            // be pulled off of the device by the user 
            if (useAccelerometer)
            { 
                sensorListener =
                        new AccelerationEventListener(useHighPassFilter, resultCallback, threshold);
                sensorManager.registerListener(sensorListener,
                        sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                        RATE);
            } 
            else 
            { 
                sensorListener =
                        new AccelerationEventListener(useHighPassFilter, resultCallback, threshold);
                sensorManager.registerListener(sensorListener,
                        sensorManager
                                .getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                        RATE);
            } 
 
            readingAccelerationData = true;
 
            Log.d(TAG, "Started reading acceleration data");
        } 
    } 
 
    public void stopReadingAccelerationData() 
    { 
        if (readingAccelerationData && sensorListener != null)
        { 
            sensorManager.unregisterListener(sensorListener);
 
            // Tell listeners to clean up after themselves 
            sensorListener.stop();
 
            readingAccelerationData = false;
Stop searching for code, let great code find you!  Add Codota to your java IDE