Dela via


SensorManager Class

Definition

SensorManager lets you access the device's android.hardware.Sensor sensors.

[Android.Runtime.Register("android/hardware/SensorManager", DoNotGenerateAcw=true)]
public abstract class SensorManager : Java.Lang.Object
[<Android.Runtime.Register("android/hardware/SensorManager", DoNotGenerateAcw=true)>]
type SensorManager = class
    inherit Object
Inheritance
SensorManager
Attributes

Remarks

SensorManager lets you access the device's android.hardware.Sensor sensors.

Always make sure to disable sensors you don't need, especially when your activity is paused. Failing to do so can drain the battery in just a few hours. Note that the system will not disable sensors automatically when the screen turns off.

<p class="note"> Note: Don't use this mechanism with a Trigger Sensor, have a look at TriggerEventListener. Sensor#TYPE_SIGNIFICANT_MOTION is an example of a trigger sensor. </p>

In order to access sensor data at high sampling rates (i.e. greater than 200 Hz for SensorEventListener and greater than SensorDirectChannel#RATE_NORMAL for SensorDirectChannel), apps must declare the android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS permission in their AndroidManifest.xml file.

public class SensorActivity extends Activity implements SensorEventListener {
                private final SensorManager mSensorManager;
                private final Sensor mAccelerometer;

                public SensorActivity() {
                    mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
                    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
                }

                protected void onResume() {
                    super.onResume();
                    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
                }

                protected void onPause() {
                    super.onPause();
                    mSensorManager.unregisterListener(this);
                }

                public void onAccuracyChanged(Sensor sensor, int accuracy) {
                }

                public void onSensorChanged(SensorEvent event) {
                }
            }

Java documentation for android.hardware.SensorManager.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

SensorManager(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

GravityDeathStarI

Gravity (estimate) on the first Death Star in Empire units (m/s^2)

GravityEarth

Earth's gravity in SI units (m/s^2)

GravityJupiter

Jupiter's gravity in SI units (m/s^2)

GravityMars

Mars' gravity in SI units (m/s^2)

GravityMercury

Mercury's gravity in SI units (m/s^2)

GravityMoon

The Moon's gravity in SI units (m/s^2)

GravityNeptune

Neptune's gravity in SI units (m/s^2)

GravityPluto

Pluto's gravity in SI units (m/s^2)

GravitySaturn

Saturn's gravity in SI units (m/s^2)

GravitySun

Sun's gravity in SI units (m/s^2)

GravityTheIsland

Gravity on the island

GravityUranus

Uranus' gravity in SI units (m/s^2)

GravityVenus

Venus' gravity in SI units (m/s^2)

LightCloudy

luminance under a cloudy sky in lux

LightFullmoon

luminance at night with full moon in lux

LightNoMoon

luminance at night with no moon in lux

LightOvercast

luminance under an overcast sky in lux

LightShade

luminance in shade in lux

LightSunlight

luminance of sunlight in lux

LightSunlightMax

Maximum luminance of sunlight in lux

LightSunrise

luminance at sunrise in lux

MagneticFieldEarthMax

Maximum magnetic field on Earth's surface

MagneticFieldEarthMin

Minimum magnetic field on Earth's surface

PressureStandardAtmosphere

Standard atmosphere, or average sea-level pressure in hPa (millibar)

StandardGravity

Standard gravity (g) on Earth.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsDynamicSensorDiscoverySupported

Tell if dynamic sensor discovery feature is supported by system.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
Sensors
Obsolete.

This member is deprecated.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

CancelTriggerSensor(TriggerEventListener, Sensor)

Cancels receiving trigger events for a trigger sensor.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CreateDirectChannel(HardwareBuffer)

Create a sensor direct channel backed by shared memory wrapped in HardwareBuffer object.

CreateDirectChannel(MemoryFile)

Create a sensor direct channel backed by shared memory wrapped in MemoryFile object.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Flush(ISensorEventListener)

Flushes the FIFO of all the sensors registered for this listener.

FromContext(Context)
GetAltitude(Single, Single)

Computes the Altitude in meters from the atmospheric pressure and the pressure at sea level.

GetAngleChange(Single[], Single[], Single[])

Helper function to compute the angle change between two rotation matrices.

GetDefaultSensor(SensorType, Boolean)

Return a Sensor with the given type and wakeUp properties.

GetDefaultSensor(SensorType)

Use this method to get the default sensor for a given type.

GetDynamicSensorList(SensorType)

Use this method to get a list of available dynamic sensors of a certain type.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetInclination(Single[])

Computes the geomagnetic inclination angle in radians from the inclination matrix <b>I</b> returned by #getRotationMatrix.

GetOrientation(Single[], Single[])

Computes the device's orientation based on the rotation matrix.

GetQuaternionFromVector(Single[], Single[])

Helper function to convert a rotation vector to a normalized quaternion.

GetRotationMatrix(Single[], Single[], Single[], Single[])

Computes the inclination matrix <b>I</b> as well as the rotation matrix <b>R</b> transforming a vector from the device coordinate system to the world's coordinate system which is defined as a direct orthonormal basis, where:

GetRotationMatrixFromVector(Single[], Single[])

Helper function to convert a rotation vector to a rotation matrix.

GetSensorList(SensorType)

Use this method to get the list of available sensors of a certain type.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
RegisterDynamicSensorCallback(SensorManager+DynamicSensorCallback, Handler)

Add a android.hardware.SensorManager.DynamicSensorCallback DynamicSensorCallback to receive dynamic sensor connection callbacks.

RegisterDynamicSensorCallback(SensorManager+DynamicSensorCallback)

Add a android.hardware.SensorManager.DynamicSensorCallback DynamicSensorCallback to receive dynamic sensor connection callbacks.

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Handler)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor.

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Int32, Handler)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

RegisterListener(ISensorEventListener, Sensor, SensorDelay, Int32)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency and the given maximum reporting latency.

RegisterListener(ISensorEventListener, Sensor, SensorDelay)

Registers a android.hardware.SensorEventListener SensorEventListener for the given sensor at the given sampling frequency.

RegisterListener(ISensorListener, Int32, SensorDelay)
Obsolete.

Registers a SensorListener for given sensors.

RegisterListener(ISensorListener, Int32)
Obsolete.

Registers a listener for given sensors.

RemapCoordinateSystem(Single[], Axis, Axis, Single[])

Rotates the supplied rotation matrix so it is expressed in a different coordinate system.

RequestTriggerSensor(TriggerEventListener, Sensor)

Requests receiving trigger events for a trigger sensor.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterDynamicSensorCallback(SensorManager+DynamicSensorCallback)

Remove a android.hardware.SensorManager.DynamicSensorCallback DynamicSensorCallback to stop sending dynamic sensor connection events to that callback.

UnregisterFromRuntime() (Inherited from Object)
UnregisterListener(ISensorEventListener, Sensor)

Unregisters a listener for the sensors with which it is registered.

UnregisterListener(ISensorEventListener)

Unregisters a listener for all sensors.

UnregisterListener(ISensorListener, Int32)
Obsolete.

Unregisters a listener for the sensors with which it is registered.

UnregisterListener(ISensorListener)
Obsolete.

Unregisters a listener for all sensors.

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to