Android Sensor

 

int TYPE_ACCELEROMETER A constant describing an accelerometer sensor type.
int TYPE_ALL A constant describing all sensor types.  NexusOne默认为 加速度
int TYPE_AMBIENT_TEMPERATURE A constant describing an ambient temperature sensor type
int TYPE_GRAVITY A constant describing a gravity sensor type.
int TYPE_GYROSCOPE A constant describing a gyroscope sensor type  回转仪?
int TYPE_LIGHT A constant describing an light sensor type.
int TYPE_LINEAR_ACCELERATION A constant describing a linear acceleration sensor type.
int TYPE_MAGNETIC_FIELD A constant describing a magnetic field sensor type.  磁场
int TYPE_ORIENTATION This constant is deprecated. use SensorManager.getOrientation() instead. 定向(指北针)和角度
int TYPE_PRESSURE A constant describing a pressure sensor type
int TYPE_PROXIMITY A constant describing an proximity sensor type.
int TYPE_RELATIVE_HUMIDITY A constant describing a relative humidity sensor type.
int TYPE_ROTATION_VECTOR A constant describing a rotation vector sensor type.
int TYPE_TEMPERATURE This constant is deprecated. use Sensor.TYPE_AMBIENT_TEMPERATURE instead.

public static float[] getOrientation (float[] R, float[] values)

Since:  API Level 3

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

When it returns, the array values is filled with the result:

  • values[0]: azimuth, rotation around the Z axis.
  • values[1]: pitch, rotation around the X axis.
  • values[2]: roll, rotation around the Y axis.

The reference coordinate-system used is different from the world coordinate-system defined for the rotation matrix:

  • X is defined as the vector product Y.Z (It is tangential to the ground at the device's current location and roughly points West).
  • Y is tangential to the ground at the device's current location and points towards the magnetic North Pole.
  • Z points towards the center of the Earth and is perpendicular to the ground.

 

 

All three angles above are in radians and positive in the counter-clockwise direction.

Parameters
R rotation matrix see getRotationMatrix(float[], float[], float[], float[]).
values an array of 3 floats to hold the result.
Returns
  • The array values passed as argument.
See Also

About Gravity Sensor

If you want to use gravity sensor in activity,you can get it by:

        SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

        Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);

Noticed that TYPE_GRAVITY maybe TYPE_ACCELERATOR or some others ,i'm not sure.

After this, create a SensorEventListener to deal with the sensor event.And then register the listener,or unregister it when closed.

However,if you want to disable the AutoRotate of the device,you should modify the settings.Remeber that,like brightness,all the functions of the device level should be modified in settings.

The following code is used to disable the auto-rotate of the device:

Uri uri = android.provider.Settings.System.getUriFor("accelerometer_rotation");

android.provider.Settings.System.putInt(getContentResolver(), "accelerometer_rotation", 0);

getContentResolver().notifyChange(uri, null);

0 is off,1 is on.

 

public static final String ACCELEROMETER_ROTATION

Since:  API Level 3

Control whether the accelerometer will be used to change screen orientation. If 0, it will not be used unless explicitly requested by the application; if 1, it will be used by default unless explicitly disabled by the application.

Constant Value: "accelerometer_rotation"

You can see all the items of the settings on:http://developer.android.com/reference/android/provider/Settings.System.html

你可能感兴趣的:(android)