Danh mục tài liệu

Bài giảng Lập trình cho thiết bị di động: Chương 7 - ĐH Công nghệ Đồng Nai

Số trang: 35      Loại file: pptx      Dung lượng: 2.38 MB      Lượt xem: 13      Lượt tải: 0    
Xem trước 4 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Bài giảng Lập trình cho thiết bị di động: Chương 7 - Thao tác với thiết bị cảm ứng có nội dung trình bày về Sensors và Monitoring the Battery. Tham khảo nội dung bài giảng để hiểu rõ hơn về các nội dung trên.
Nội dung trích xuất từ tài liệu:
Bài giảng Lập trình cho thiết bị di động: Chương 7 - ĐH Công nghệ Đồng Nai DONG NAI UNIVERSITY OF TECHNOLOGY 1. Sensors2. Monitoring the Battery 1 DONG NAI UNIVERSITY OF TECHNOLOGY1. SensorsThe emulator does not provide any sensor data. All sensortesting must be done on a physical device. Alternatively,OpenIntents.org also provides a handy Sensor Simulator:http://code.google.com/p/openintents/wiki/SensorSimulatorThis tool simulates accelerometer, compass, andtemperature sensors, and it transmits data to the emulator.Android devices have a variety of sensors : 2 DONG NAI UNIVERSITY OF TECHNOLOGY 1. SensorsTYPE_ACCELEROMETER: Measures acceleration in threedirections; values are in SI units (m/s2).TYPE_GYROSCOPE: Measures angular orientation in threedirections; values are angles in degrees.TYPE_LIGHT: Measures ambient light; values are in SI luxunits.TYPE_MAGNETIC_FIELD: Measures magnetism in threedirections; 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 CommentSensor Class representing a sensor. Use getSensorList(int) to get the list of available Sensors.SensorEve This class represents a Sensor event andnt holds informations such as the sensors type, the time-stamp, accuracy and of course the sensors data.SensorEventListe An interface: Used for receiving notificationsner from the SensorManager when sensor values have changed.SensorManag SensorManager lets you access the deviceser sensors. Get an instance of this class by calling Context.getSystemService() with the 4 DONG NAI UNIVERSITY OF TECHNOLOGY1. Sensors Ø Working with Sensorü To get a Sensor, you need to use SensorManager. 5 DONG NAI UNIVERSITY OF TECHNOLOGY1. Sensors Ø Working with Sensorü Register EventListener to it. 6 DONG NAI UNIVERSITY OF TECHNOLOGY1. Sensors Ø Working with Sensorü UnRegister EventListener.Register in the onResume method andUnregister in the onPause method 7 DONG NAI UNIVERSITY OF TECHNOLOGY1. SensorsØ SensorManager.SENSOR_DELAY Frequence CommentSENSOR_DELAY_FASTE get sensor data as fast asST possibleSENSOR_DELAY_NORM rate (default) suitable forAL screen orientation changesSENSOR_DELAY_GAME rate suitable for gamesSENSOR_DELAY_UI rate suitable for the user interface 8 DONG NAI UNIVERSITY OF TECHNOLOGY1. 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 public int accuracy The accuracy of this event. public Sensor sensor The sensor that generated this event. public long timestamp The time in nanosecond at which the event happenedpublic final float[] values The length and contents of the values array depends on which sensor type is being monitored. 10 DONG NAI UNIVERSITY OF TECHNOLOGY1. Sensors Ø Sensor.TYPE_TEMPERATU RE 11 DONG NAI UNIVERSITY OF TECHNOLOGY1. Sensors Ø Sensor.TYPE_TEMPERATU ...