FileDocCategorySizeDatePackage
Sensors.javaAPI DocAndroid 1.5 API9412Wed May 06 22:41:08 BST 2009com.example.android.apis.os

Sensors

public class Sensors extends android.app.Activity

Application that displays the values of the acceleration sensor graphically.

This demonstrates the {@link android.hardware.SensorManager android.hardware.SensorManager} class.

Demo

OS / Sensors

Source files

src/com.example.android.apis/os/Sensors.java Sensors

Fields Summary
private static final String
TAG
Tag string for our debug logs
private android.hardware.SensorManager
mSensorManager
private GraphView
mGraphView
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle savedInstanceState)
Initialization of the Activity after it is first created. Must at least call {@link android.app.Activity#setContentView setContentView()} to describe what is to be displayed in the screen.

        // Be sure to call the super class.
        super.onCreate(savedInstanceState);

        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        mGraphView = new GraphView(this);
        setContentView(mGraphView);
    
protected voidonResume()

        super.onResume();
        mSensorManager.registerListener(mGraphView, 
                SensorManager.SENSOR_ACCELEROMETER | 
                SensorManager.SENSOR_MAGNETIC_FIELD | 
                SensorManager.SENSOR_ORIENTATION,
                SensorManager.SENSOR_DELAY_FASTEST);
    
protected voidonStop()

        mSensorManager.unregisterListener(mGraphView);
        super.onStop();