đây là bộ giáo trình học Android giành cho những người mới bắt đầu... bộ giáo trình bao gồm tất cả nội dung cơ bản giành cho những người mới bắt đầu lập trình Android , đây là bộ giáo trình học Android giành cho những người mới bắt đầu... bộ giáo trình bao gồm tất cả nội dung cơ bản giành cho những người mới bắt đầu lập trình Android
HO CHI MINH UNIVERSITY OF INDUSTRY 1 1. Sensors 2. Monitoring the Battery HO CHI MINH UNIVERSITY OF INDUSTRY 2 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: http://code.google.com/p/openintents/wiki/SensorSimulator This tool simulates accelerometer, compass, and temperature sensors, and it transmits data to the emulator. Android devices have a variety of sensors : HO CHI MINH UNIVERSITY OF INDUSTRY 3 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. HO CHI MINH UNIVERSITY OF INDUSTRY 4 1. Sensors Here are the major classes related to sensor. Class Comment Sensor Class representing a sensor. Use getSensorList(int) to get the list of available Sensors. SensorEvent 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. 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. HO CHI MINH UNIVERSITY OF INDUSTRY 5 1. Sensors Working with Sensor To get a Sensor, you need to use SensorManager. HO CHI MINH UNIVERSITY OF INDUSTRY 6 1. Sensors Working with Sensor Register EventListener to it. HO CHI MINH UNIVERSITY OF INDUSTRY 7 1. Sensors Working with Sensor UnRegister EventListener. Register in the onResume method and Unregister in the onPause method HO CHI MINH UNIVERSITY OF INDUSTRY 8 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 rate suitable for games SENSOR_DELAY_UI rate suitable for the user interface HO CHI MINH UNIVERSITY OF INDUSTRY 9 1. Sensors Receive SensorEvent Normally, onSensorChanged is the method in which we need to put your sensor handle logic. HO CHI MINH UNIVERSITY OF INDUSTRY 10 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 happened public final float[] values The length and contents of the values array depends on which sensor type is being monitored. [...]... areas where behavior can be modified to improve battery life, which would be appreciated by users To monitor the battery, the application must have the BATTERY_STATS permission: 30 HO CHI MINH UNIVERSITY OF INDUSTRY 2 Monitoring the Battery Then the application needs to register for a particular BroadcastIntent In this case, it must . (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 . 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. SensorEventListener An interface: Used. Sensors Working with Sensor Register EventListener to it. HO CHI MINH UNIVERSITY OF INDUSTRY 7 1. Sensors Working with Sensor UnRegister EventListener. Register in the onResume method