Bài giảng Lập trình cho thiết bị di động - Chương 3: Thao tác với thiết bị cảm ứng - Trần Duy Thanh
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
2. Monitoring
the Battery
1
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
The emulator does not provide any sensor data. All sensor
testing must be done on a physical device. Alternatively,
OpenIntents.org also provides a handy Sensor Simulator:
temperature sensors, and it transmits data to the emulator.
Android devices have a variety of sensors :
2
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
TYPE_ACCELEROMETER: Measures acceleration in three
directions; values are in SI units (m/s2).
TYPE_GYROSCOPE: Measures angular orientation in three
directions; values are angles in degrees.
TYPE_LIGHT: Measures ambient light; values are in SI lux
units.
TYPE_MAGNETIC_FIELD: Measures magnetism in three
directions; the compass values are in micro-Tesla (uT).
TYPE_PRESSURE: Measures barometric pressure.
TYPE_PROXIMITY: Measures the distance to an object;
values are in centimeters, or “near” versus “far.”
TYPE_RELATIVE_HUMIDITY: Measures the relative humidity.
TYPE_AMBIENT_TEMPERATURE: Measures temperature.
3
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢Here are the major classes related to sensor.
Class
Comment
Class representing a sensor. Use getSensorList(int)
to get the list of available Sensors.
Sensor
This class represents a Sensor event and holds
informations such as the sensor's type, the time-
stamp, accuracy and of course the sensor's data.
SensorEvent
SensorEventListener
An interface: Used for receiving notifications from
the SensorManager when sensor values have
changed.
SensorManager SensorManager lets you access the device's
sensors. Get an instance of this class by calling
Context.getSystemService() with the argument
SENSOR_SERVICE.
4
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
✓ To get a Sensor, you need to use SensorManager.
➢ Working with Sensor
5
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
✓ Register EventListener to it.
➢ Working with Sensor
6
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Working with Sensor
✓ UnRegister EventListener.
Register in the onResume method and
Unregister in the onPause method
7
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ SensorManager.SENSOR_DELAY
Frequence
Comment
SENSOR_DELAY_FASTEST
get sensor data as fast as
possible
SENSOR_DELAY_NORMAL
rate (default) suitable for screen
orientation changes
SENSOR_DELAY_GAME
SENSOR_DELAY_UI
rate suitable for games
rate suitable for the user
interface
8
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Receive SensorEvent
Normally, onSensorChanged is the method in which
we need to put your sensor handle logic.
9
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ SensorEvent
Type
Name
Comment
The sensor that generated this
event.
the event happened
public final float[] values
The length and contents of
monitored.
10
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor.TYPE_TEMPERATURE
11
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor.TYPE_TEMPERATURE
12
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor.TYPE_LIGHT
13
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor.TYPE_LIGHT
14
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor.TYPE_PRESSURE
15
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor.TYPE_PRESSURE
16
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor. TYPE_PROXIMITY
17
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor. TYPE_PROXIMITY
18
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor. TYPE_PROXIMITY
19
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Sensors
➢ Sensor.TYPE_ACCELEROMETER
The accelerometer values are represented in SI units
(m/s2). The device at right has the bottom of the device
screen pointing toward the center of gravity. Gravity on
Earth is 9.80665 m/s2.
All values are in SI units (m/s2)
values[0]: Acceleration minus Gx on
the x-axis
values[1]: Acceleration minus Gy on
the y-axis
values[2]: Acceleration minus Gz on
the z-axis
20
Tải về để xem bản đầy đủ
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Lập trình cho thiết bị di động - Chương 3: Thao tác với thiết bị cảm ứng - Trần Duy Thanh", để tải tài liệu gốc về máy hãy click vào nút Download ở trên
File đính kèm:
bai_giang_lap_trinh_cho_thiet_bi_di_dong_chuong_3_thao_tac_v.pptx

