Android sensor programming experience

Source: Internet
Author: User

The Android mobile phone operating system is an open-source operating system that allows users to flexibly program to meet their various needs. Before learning this system, let's take a look at the Android sensor applications. In the past two days, I have studied Android sensor programming with mobile phones. Now I want to make a summary:

  • How to Use Android Spinner
  • Interpretation of basic concepts of Android applications
  • Android HttpURLConnection application tips
  • Analysis of the correct Android timer Application Method
  • Android local application Application Method

1. The positive and negative directions of the x, y, and Z axes of the Accelrator:

When the mobile phone screen is placed horizontally up: (x, y, z) = (0, 0,-10) instead of (0, 0, 10)

When the phone is lifted at the top, y decreases and the value is negative.

When the mobile phone is lifted at the bottom: y increases and is positive

When the right side of the mobile phone is lifted: x decreases and is negative.

When the left side of the mobile phone is lifted: x increases and the value is positive.

2. Change of the Z axis of the Accelrator:

Z =-10

When the mobile phone screen is placed vertically, z = 0

When the mobile phone screen is placed horizontally down, z = 10

3. When x is changed to + 5, the mobile phone screen changes to vertical.

When x changes to-5, the mobile phone screen changes to horizontal

4. classes related to Android sensors are different in SDK1.1 and SDK1.5, so the implementation code is different.

5. Android sensor types include: direction, acceleration table, light, magnetic field, closeness, temperature, etc.

In the program:

Direction: SensorManager. SENSOR_ORIENTATION,

Acceleration table: SensorManager. SENSOR_ACCELEROMETER

Light: SensorManager. SENSOR_LIGHT

Magnetic Field: SensorManager. SENSOR_MAGNETIC_FIELD

Closeness: SensorManager. SENSOR_PROXIMITY

Temperature: SensorManager. SENSOR_TEMPERATURE

Sampling Rate: the fastest, game, common, and user interface. When an application requests a specific sampling rate, it only prompts or recommends the Android sensor subsystem. The specified sampling rate is not guaranteed.

Fastest: SensorManager. SENSOR_DELAY_FASTEST

Game: SensorManager. SENSOR_DELAY_GAME

Normal: SensorManager. SENSOR_DELAY_NORMAL

User Interface: SensorManager. SENSOR_DELAY_UI

Accuracy: High, low, medium, and unreliable.

6. Definitions of three coordinates of Orientation Sensor:

Values [0]: horizontal rotation angle of the azimuth angle). Simply put, it is the orientation of the head of the mobile phone, 0 = North, 90 = east, 180 = South, 270 = West, but it seems not accurate)

Values [1]: Vertical Rotation Angle, 0 = face flat,-90 = vertical up,-180/180 = face flat, 90 = vertical down

Values [2]: rotate to the rotation angle, 0 = forward, 90 = backward to right,-90 = backward to left

7. Automatically redirect mobile phones

If you want your phone to be automatically rotated, you only need to go to AndroidManifest. in xml, it is good to change ORIENTAION to sensor, but if you want to change the Activity orientation, You need to grasp the Display of the Activity:

 
 
  1. if (getWindowManager().getDefaultDisplay().getOrientation() == 0) {   
  2. //Do some portrait   
  3. } else {   
  4. //Do some Landscape  

Note that the constant numbers in the Android sensor are different from those in ActivityInfo. 0 is straight and 1 is complete. In the future, because a string of onPause, onDestory, and onCreate will be generated for each change to the screen direction, all the operations required will be completed in onCreate.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.