1. Trang chủ
  2. » Công Nghệ Thông Tin

bài học Android cơ bản

35 582 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 35
Dung lượng 2,34 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

đâ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

Trang 1

1 Sensors

2 Monitoring

the Battery

Trang 2

temperature sensors, and it transmits data to the emulator.

Android devices have a variety of sensors :

Trang 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.

Trang 4

1 Sensors

 Here are the major classes related to sensor

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 stamp, accuracy and of course the sensor's data

time-SensorEventListener An interface: Used for receiving notifications from

the SensorManager when sensor values have

changed

SensorManager SensorManager lets you access the device's

Trang 5

1 Sensors  Working with Sensor

 To get a Sensor, you need to use SensorManager

Trang 6

1 Sensors  Working with Sensor

 Register EventListener to it

Trang 7

1 Sensors  Working with Sensor

 UnRegister EventListener

Register in the onResume method and

Unregister in the onPause method

Trang 8

screen orientation changesSENSOR_DELAY_GAME rate suitable for games

SENSOR_DELAY_UI rate suitable for the user

interface

Trang 9

1 Sensors

 Receive SensorEvent

Normally, onSensorChanged is the method in which

we need to put your sensor handle logic

Trang 10

1 Sensors

 SensorEvent

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

Trang 11

1 Sensors  Sensor.TYPE_TEMPERATURE

Trang 12

1 Sensors  Sensor.TYPE_TEMPERATURE

Trang 13

1 Sensors  Sensor.TYPE_LIGHT

Trang 14

1 Sensors  Sensor.TYPE_LIGHT

Trang 15

1 Sensors  Sensor.TYPE_PRESSURE

Trang 16

1 Sensors  Sensor.TYPE_PRESSURE

Trang 17

1 Sensors  Sensor TYPE_PROXIMITY

Trang 18

1 Sensors  Sensor TYPE_PROXIMITY

Trang 19

1 Sensors  Sensor TYPE_PROXIMITY

Trang 20

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

Trang 21

1 Sensors  Sensor.TYPE_ACCELEROMETER

Use to Accelerometer to detect SHAKING Device

Trang 22

1 Sensors  Sensor.TYPE_ACCELEROMETER

Trang 23

1 Sensors  Sensor.TYPE_ACCELEROMETER

Trang 24

1 Sensors  Sensor.TYPE_GYROSCOPE

measure, or maintain, the orientation of a device

rate of rotation around a particular axis

values[0]: Angular speed around the x-axis

values[1]: Angular speed around the y-axis

values[2]: Angular speed around the z-axis

Trang 25

1 Sensors  Sensor.TYPE_GYROSCOPE

Trang 26

1 Sensors  Sensor.TYPE_GYROSCOPE

Trang 27

1 Sensors  Sensor.TYPE_ORIENTATION

All values are angles in degrees:

values[0]: Azimuth, angle between the

magnetic north direction and the y-axis,

around the z-axis (0 to 359) 0=North,

90=East, 180=South, 270=West

values[1]: Pitch, rotation around x-axis (-180

to 180), with positive values when the z-axis

moves toward the y-axis

values[2]: Roll, rotation around y-axis (-90 to

90), with positive values when the x-axis

moves toward the z-axis

Trang 28

1 Sensors  Sensor.TYPE_ORIENTATION

Trang 29

1 Sensors

Exercise : Using Sensors Accelerometor and Proximity to build an AlbumManager application:

- Nice GUI to display Pictures

- When Device was shaken to Left  open the Previous Picture

- When Device was shaken to Right open the Next Picture

- When Proximity is active and event.values[0]==0.0  Close the AlbumManager application

Trang 30

2 Monitoring the Battery

 A monitoring application can reduce the monitoring

frequency when the battery is low and can increase it if

the device is powered by an external power source The battery levels can also help indicate the efficiency of an

application, allowing developers to find 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:

<uses-permission android:name=

Trang 31

2 Monitoring the Battery

Then the application needs to register for a particular

BroadcastIntent In this case, it must be

Intent.ACTION_BATTERY_CHANGED.

Trang 32

2 Monitoring the Battery

Trang 33

2 Monitoring the Battery

Trang 34

2 Monitoring the Battery

Trang 35

35

Ngày đăng: 06/07/2014, 18:36

TỪ KHÓA LIÊN QUAN

w