Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng...

40
Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trên ươ ế ơ Android 1.1 H đi u hành Android 1.1.1 H đi u hành Android. Các lo i thi t b cài đ t ế Android Android là m t h đi u hành dành cho thi t b di đ ng nh đi n tho i, máy ế ư tính b ng và netbooks. Android đ c phát tri n b i Google, d a trên n n t ng ượ Linux và các ph n m m mã ngu n m . Android đ c phát tri n nh m c nh tranh ượ v i các h đi u hành di đ ng khác nh iOS (Apple), BlackBerry OS (BlackBerry), ư Windows Mobile (Microsoft), Symbian(Nokia). Bada (Samsung) ... Trên đi n tho i di đ ng Công ty nghiên c u th tr ng Canalys đã c tính trong quý 2 năm ườ ướ 2009 r ng Android có 2,8% th ph n đi n tho i thông minh đ c bán ra toàn ượ c u. Đ n quý 4 năm 2010 con s này tăng lên 33% th ph n, tr thành n n t ng ế đi n tho i thông minh bán ch y hàng đ u. Đ n quý 3 năm 2011 Gartner c tính ế ướ r ng h n m t n a (52,5%) th tr ng đi n tho i thông minh thu c v Android ơ ườ Đ n quý 3 năm 2012 Android đã có 75% th ph n đi n tho i thông minh toàn c u ế theo nghiên c u c a hãng IDC. (Ngu n http://vi.wikipedia.org/wiki/Andoid). Trên lãnh v c máy tính b ng, Công ty nghiên c u th tr ng IDC v a đ a ra d báo ườ ư r ng th ph n c a máy tính b ng Android có th s đ t m c cao nh t là 48,8% trong năm nay (2013) (Theo http://tintuc.vnn.vn/)

Transcript of Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng...

Page 1: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Ch ng 1 Caacutec ki n th c c b n dugraveng cho l p trigravenh ng d ng trecircnươ ế ứ ơ ả ậ ứ ụ Android

11 H đi u hagravenh Androidệ ề111 H đi u hagravenh Android Caacutec lo i thi t b cagravei đ t ệ ề ạ ế ị ặ Android

Android lagrave m t h đi u hagravenh dagravenh cho thi t b di đ ng nh đi n tho i maacuteyộ ệ ề ế ị ộ ư ệ ạ

tiacutenh b ng vagrave netbooks Android đ c phaacutet tri n b i Google d a trecircn n n t ngả ượ ể ở ự ề ả

Linux vagrave caacutec ph n m m matilde ngu n mầ ề ồ ở Android đ c phaacutet tri n nh m c nh tranhượ ể ằ ạ

v i caacutec h đi u hagravenh di đ ng khaacutec nh iOS (Apple) BlackBerry OS (BlackBerry)ớ ệ ề ộ ư

Windows Mobile (Microsoft) Symbian(Nokia) Bada (Samsung) Trecircn đi nệ

tho i di đ ng ạ ộ Cocircng ty nghiecircn c u th tr ng Canalys đatilde c tiacutenh trong quyacute 2 nămứ ị ườ ướ

2009 r ng Android coacute 28 th ph n đi n tho i thocircng minh đ c baacuten ra toagravenằ ị ầ ệ ạ ượ

c u Đ n quyacute 4 năm 2010 con s nagravey tăng lecircn 33 th ph n tr thagravenh n n t ngầ ế ố ị ầ ở ề ả

đi n tho i thocircng minh baacuten ch y hagraveng đ u Đ n quyacute 3 năm 2011 Gartner c tiacutenhệ ạ ạ ầ ế ướ

r ng h n m t n a (525) th tr ng đi n tho i thocircng minh thu c v Androidằ ơ ộ ử ị ườ ệ ạ ộ ề

Đ n quyacute 3 năm 2012 Android đatilde coacute 75 th ph n đi n tho i thocircng minh toagraven c uế ị ầ ệ ạ ầ

theo nghiecircn c u c a hatildeng IDC (Ngu n ứ ủ ồ httpviwikipediaorgwikiAndoid) Trecircn

latildenh v c maacutey tiacutenh b ng ự ả Cocircng ty nghiecircn c u th tr ng IDC v a đ a ra d baacuteoứ ị ườ ừ ư ự

r ng th ph n c a maacutey tiacutenh b ng Android coacute th s đ t m c cao nh t lagrave 488ằ ị ầ ủ ả ể ẽ ạ ứ ấ

trong năm nay (2013) (Theo httptintucvnnvn)

D baacuteo th ph n c a caacutec h đi u hagravenh dagravenh cho maacutey tiacutenh b ng ự ị ầ ủ ệ ề ả

trong năm 2013 vagrave 2017 (ngu n IDC)ồ

Android coacute m t c ng đ ng phaacutet tri n ng d ng l n AppBrain - trang web cungộ ộ ồ ể ứ ụ ớ

c p caacutec ng d ng Android t t nh t th ng kecirc r ng tiacutenh đ n thaacuteng 042012 Googleấ ứ ụ ố ấ ố ằ ế

Play đang s h u 430000 ng d ng trong đoacute 311000 (72) ng d ng mi n phiacuteở ữ ứ ụ ứ ụ ễ

Caacutec thi t b cagravei đ t ế ị ặ Android r t đa d ng v kiacutech th c vagrave ch ng lo i H đi uấ ạ ề ướ ủ ạ ệ ề

hagravenh Android coacute th ch y trecircn caacutec lo i thi t b sauể ạ ạ ế ị

Đi n tho i thocircng minh (Smartphone)ệ ạ

Maacutey tiacutenh b ng (Tablet)ả

Caacutec thi t b đ c đi n t (E-reader devices)ế ị ọ ệ ử

Netbook

Maacutey nghe nh c MP4ạ

Internet Tivi Smart TV

112 Caacutec phiecircn b n Androidả

(Tham kh o ngu n ả ồ httpenwikipediaorgwikiAndroid_version_history

httpnhipsongsotuoitrevnKien-thuc-Cong-nghe519360Luoc-su-Android-qua-

cac-phien-banhtml)

Phiecircn b n 10 ả

o Ngagravey cocircng b ố 23-11-2008

o Tecircn matilde Astro Boy hay Bender

o Phiecircn b n Linux kernel 2625ả

o Tiacutenh năng

+ Android 10 r t nguyecircn s tiacutech h p s n kh năng đ ng bấ ơ ợ ẵ ả ồ ộ

d li u v i caacutec d ch v tr c tuy n c a Google nh Gmailữ ệ ớ ị ụ ự ế ủ ư

Google Calendar vagrave Contacts m t trigravenh phaacutet media h trộ ỗ ợ

Wi-Fi vagrave Bluetooth thanh tr ng thaacutei hi n th caacutec thocircng baacuteoạ ể ị

ng d ng vagrave m t ng d ng ch p nh (camera) tuy ch a choứ ụ ộ ứ ụ ụ ả ư

pheacutep thay đ i đ phacircn gi i vagrave ch t l ng nhổ ộ ả ấ ượ ả

Phiecircn b n 1ả 5

o Ngagravey cocircng b ố 30-4-2009

o Tecircn matilde Cupcake

o Phiecircn b n Linux kernel 2627ả

o Tiacutenh năng

+ Cupcake mang nhi u tiacutenh năng m i nh bagraven phiacutem o coacute khề ớ ư ả ả

năng d đoaacuten t đang gotilde t đi n t ng do ng i dugraveng đ tự ừ ừ ể ừ ữ ườ ặ

ra h tr widget trecircn giao di n quay phim vagrave phaacutet l i videoỗ ợ ệ ạ

clip l c s th i gian cu c g i ch đ t đ ng xoay magravenượ ử ờ ộ ọ ế ộ ự ộ

higravenh theo h ng s d ng Trigravenh duy t web trong Cupcake coacuteướ ử ụ ệ

thecircm kh năng sao copypasteả

Phiecircn b n 1ả 6

o Ngagravey cocircng b ố 30-9-2009

o Tecircn matilde Donut

o Phiecircn b n Linux kernel 2629ả

o Tiacutenh năng

+ Cung c p ch c nan g tigravem ki m nhanh đ c văn b nấ ứ ư ế ọ ả xoacutea

nhi u file nh cugraveng luacutec ề ả

Phiecircn b n ả 20

o Ngagravey cocircng b ố 26-10-2009

o Tecircn matilde Eacuteclair

o Phiecircn b n Linux kernel 2629ả

o Tiacutenh năng

+ Cho pheacutep qu n lyacute nhi u tagravei kho n Email tigravem ki m tin nh nả ề ả ế ắ

Tigravem ki m b ng gi ng noacutei Google map H ng đ n caacutec thế ằ ọ ướ ế ế

h smartphone magraven higravenh l nệ ớ

Phiecircn b n ả 22

o Ngagravey cocircng b ố 20-5-2010

o Tecircn matilde Froyo

o Phiecircn b n Linux kernel 2632ả

o Tiacutenh năng

+ H tr Flash cho pheacutep bi n chi c smartphone thagravenh thi t bỗ ợ ế ế ế ị

phaacutet soacuteng Wi-Fi cho pheacutep cagravei đ t ng d ng lecircn th nh SDặ ứ ụ ẻ ớ

thay vigrave m c đ nh cagravei ngay vagraveo b nh trong c a thi t b m tặ ị ộ ớ ủ ế ị ậ

kh u đatilde h tr s vagrave ch s ẩ ỗ ợ ố ữ ố

Phiecircn b n ả 23

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Gingerbread

o Phiecircn b n Linux kernel 2635ả

o Tiacutenh năng

+ H tr thi t k giao di n đ n gi n vagrave hi u qu Nh p vănỗ ợ ế ế ệ ơ ả ệ ả ậ

b n thocircng minh vagrave nhanh h n h tr ch c năng copy vagrave daacutenả ơ ỗ ợ ứ

h tr tiacutenh năng d n raacutecỗ ợ ọ Đ n cu i năm 2012 Gingerbreadế ố

v n đang ph soacuteng trecircn r t nhi u thi t b dugraveng Androidẫ ủ ấ ề ế ị

chi m đ n h n phacircn n a (54)ế ế ơ ử

Phiecircn b n ả 30

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Honeycomb

o Phiecircn b n Linux kernel 2636ả

o Tiacutenh năng

+ Đacircy coacute th xem lagrave m t th h Android đ u tiecircn dagravenh riecircngể ộ ế ệ ầ

cho maacutey tiacutenh b ng (tablet)ả Android 30 c i ti n giao di n phugraveả ế ệ

h p v i caacutech s d ng maacutey tiacutenh b ng bagraven phiacutem o thacircn thi nợ ớ ử ụ ả ả ệ

h n h tr x lyacute đa taacutec v (multi-tasking) cho pheacutep chuy nơ ỗ ợ ử ụ ể

đ i qua l i caacutec ng d ng đang cugraveng ch y Ph n lotildei h th ngổ ạ ứ ụ ạ ầ ệ ố

coacute caacutec c i ti n t ng thiacutech v i ph n c ng nh h tr chip xả ế ươ ớ ầ ứ ư ỗ ợ ử

lyacute (CPU) đa lotildei tăng t c ph n c ngố ầ ứ

Phiecircn b n ả 40

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Ice Cream Sandwich

o Phiecircn b n Linux kernel 301ả

o Tiacutenh năng

+ Đacircy lagrave s k t h p c a phiecircn b n 3x cho maacutey tiacutenh b ng vagraveự ế ợ ủ ả ả

2x cho đi n tho i di đ ng Phiecircnb n nagravey coacute caacutec tiacutenh năng uệ ạ ộ ả ư

vi t nh giao di n đ p h n widget coacute th thay đ i kiacutechệ ư ệ ẹ ơ ể ổ

th c cho pheacutep khoacutea magraven higravenh ướ

Phiecircn b n ả m i nh t 42 ớ ấ

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Jelly Bean

o Phiecircn b n Linux kernel 34ả

o Tiacutenh năng

+ Android 42 ti p t c mang đ n nh ng c i ti n h p d n choế ụ ế ữ ả ế ấ ẫ

ng d ng ch p nh (Camera) nh ứ ụ ụ ả ư ch p nh trung th c HDRụ ả ự

(High Dynamic Range) ch o nh r ng Photo Sphere hi uụ ả ộ ệ

ng nh tigravem ki m thocircng minh vagrave đ p h n Google Now đ aứ ả ế ẹ ơ ư

tiacutenh năng l t ch n t r t hay trong bagraven phiacutem o Ch c năngướ ọ ừ ấ ả ứ

h tr nhi u tagravei kho n ng i dugraveng (multi-user profile) l nỗ ợ ề ả ườ ầ

đ u tiecircn đ c aacutep d ng trong Android 42 nh ng ch coacute ng iầ ượ ụ ư ỉ ườ

dugraveng maacutey tiacutenh b ng th a h ng ch c năng nagraveyả ừ ưở ứ

Đ n cu i năm 2012ế ố v n cograven đ n 54 thi t b Android dugraveng Gingerbreadẫ ế ế ị

(Android 23) Ice Cream Sandwich (Android 40) theo sau v i 258 Th hớ ế ệ

Jelly Bean m i nh t cograven khaacute iacutet i v i 27 thi t b s d ngớ ấ ỏ ớ ế ị ử ụ

113 u vagrave nh c đi m c a AndroidƯ ượ ể ủ

Vigrave Android lagrave h đi u hagravenh matilde ngu n mệ ề ồ ở necircn coacute nh ng u vagrave nh c đi mữ ư ượ ể

sau

1131 u đi mƯ ể

An ninh Caacutec l i nhanh choacuteng đ c phaacutet hi n vagrave s a đ iỗ ượ ệ ử ổ

Ch t l ngấ ượ Caacutec ng d ng khocircng ng ng đ c c i ti n phugrave h p v i nhuứ ụ ừ ượ ả ế ợ ớ

c u s d ng c a nhi u ng iầ ử ụ ủ ề ườ

Kh năng tugravey bi nả ế Nh ng đo n matilde trong ch ng trigraven đ c cocircng khaiữ ạ ươ ượ

necircn ng i dugraveng coacute th thecircm b t caacutec ch c năng tuacutey yacute mu nườ ể ớ ứ ố

Chi phiacute S d ng s n ph m matilde ngu n m hoagraven toagraven khocircng t n phiacute ti tử ụ ả ẩ ồ ở ố ế

ki m kinh phiacuteệ

1132 Nh c đi mượ ể

Kh năng b o m t ả ả ậ Vigrave Android lagrave h đi u hagravenh matilde ngu n m necircn t tệ ề ồ ở ấ

c caacutec thocircng tin v h th ng m i ng i đ u n m đ c Đacircy lagrave u đi mả ề ệ ố ọ ườ ề ắ ượ ư ể

vagrave cũng lagrave nh c đi m b i vigrave caacutec hacker coacute th tigravem ki m nh ng l h ngượ ể ở ể ế ữ ỗ ổ

h th ng vagrave t o ra nh ng matilde đ cệ ố ạ ữ ộ

114 N n t ng h đi u hagravenh Androidề ả ệ ề

httpsdocsgooglecomdocumentpreview

hgd=1ampid=1ehWmLcA4DmeQ2GDYqzBvUyby3BwdUHRMuaP_6tX7dOMamppli=1

1141 Caacutec thagravenh ph n c a Androidầ ủ

L c đ sau th hi n caacutec thagravenh ph n c a h đi u hagravenh Androidượ ồ ể ệ ầ ủ ệ ề

Coacute 5 t ng phacircn bi t trong h th ng Androidầ ệ ệ ố

Applications

H đi u hagravenh Android tiacutech h p s n m t s ng d ng c b n nh emailệ ề ợ ẳ ộ ố ứ ụ ơ ả ư

client SMS l ch đi n t b n đ trigravenh duy t web s liecircn l c vagrave m t s ngị ệ ử ả ồ ệ ổ ạ ộ ố ứ

d ng khaacutec Ngoagravei ra t ng nagravey cũng chiacutenh lagrave t ng ch a caacutec ng d ng đ c phaacutetụ ầ ầ ứ ứ ụ ượ

tri n b ng ngocircn ng Javaể ằ ữ

Application Framework

Trong t ng nagravey thagravenh ph n quan tr ng nh t lagrave Acitivity Manager vigrave noacute qu nầ ầ ọ ấ ả

lyacute vograveng đ i c a m t Activityờ ủ ộ

T ng nagravey ch a caacutec th vi n Java h tr ng i dugraveng giao ti p v i t ngầ ứ ư ệ ỗ ợ ườ ế ớ ầ

Android Framework M t ph n c a th vi n nagravey do Google cung c p s n m tộ ầ ủ ư ệ ấ ẵ ộ

ph n do ta t o ra Nh v y caacutec nhagrave phaacutet tri n ng d ng coacute kh năng t o ra caacutecầ ạ ờ ậ ể ứ ụ ả ạ

ng d ng vocirc cugraveng saacuteng t o vagrave phong phuacute Caacutec nhagrave phaacutet tri n ng d ng đ c tứ ụ ạ ể ứ ụ ượ ự

do s d ng caacutec tiacutenh năng cao c p c a thi t b ph n c ng nh thocircng tin đ nh vử ụ ấ ủ ế ị ầ ứ ư ị ị

APPLICATIONS

Home Contacts Phone Browser hellip

Home

APPLICATION FRAMEWORK

Activity Manager Windows Manager Content Provider View System Package Manager

Telephony Manager Resource Manager Location Manager Notification Manager

Home

LIBRARIES

Surface Manager Media Framework SQLite

OpenGL | ES Free Type Webkit

SGL SSL libc

ANDROID RUNTIME

Core Libraries

Davik Virtual Machine

Home

LINUX KERNEL

Display Driver Camera Driver Flash Memory Driver Binder (IPC) Driver

KeyPad Driver Wifi Driver Audi Driver Power Management

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 2: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

D baacuteo th ph n c a caacutec h đi u hagravenh dagravenh cho maacutey tiacutenh b ng ự ị ầ ủ ệ ề ả

trong năm 2013 vagrave 2017 (ngu n IDC)ồ

Android coacute m t c ng đ ng phaacutet tri n ng d ng l n AppBrain - trang web cungộ ộ ồ ể ứ ụ ớ

c p caacutec ng d ng Android t t nh t th ng kecirc r ng tiacutenh đ n thaacuteng 042012 Googleấ ứ ụ ố ấ ố ằ ế

Play đang s h u 430000 ng d ng trong đoacute 311000 (72) ng d ng mi n phiacuteở ữ ứ ụ ứ ụ ễ

Caacutec thi t b cagravei đ t ế ị ặ Android r t đa d ng v kiacutech th c vagrave ch ng lo i H đi uấ ạ ề ướ ủ ạ ệ ề

hagravenh Android coacute th ch y trecircn caacutec lo i thi t b sauể ạ ạ ế ị

Đi n tho i thocircng minh (Smartphone)ệ ạ

Maacutey tiacutenh b ng (Tablet)ả

Caacutec thi t b đ c đi n t (E-reader devices)ế ị ọ ệ ử

Netbook

Maacutey nghe nh c MP4ạ

Internet Tivi Smart TV

112 Caacutec phiecircn b n Androidả

(Tham kh o ngu n ả ồ httpenwikipediaorgwikiAndroid_version_history

httpnhipsongsotuoitrevnKien-thuc-Cong-nghe519360Luoc-su-Android-qua-

cac-phien-banhtml)

Phiecircn b n 10 ả

o Ngagravey cocircng b ố 23-11-2008

o Tecircn matilde Astro Boy hay Bender

o Phiecircn b n Linux kernel 2625ả

o Tiacutenh năng

+ Android 10 r t nguyecircn s tiacutech h p s n kh năng đ ng bấ ơ ợ ẵ ả ồ ộ

d li u v i caacutec d ch v tr c tuy n c a Google nh Gmailữ ệ ớ ị ụ ự ế ủ ư

Google Calendar vagrave Contacts m t trigravenh phaacutet media h trộ ỗ ợ

Wi-Fi vagrave Bluetooth thanh tr ng thaacutei hi n th caacutec thocircng baacuteoạ ể ị

ng d ng vagrave m t ng d ng ch p nh (camera) tuy ch a choứ ụ ộ ứ ụ ụ ả ư

pheacutep thay đ i đ phacircn gi i vagrave ch t l ng nhổ ộ ả ấ ượ ả

Phiecircn b n 1ả 5

o Ngagravey cocircng b ố 30-4-2009

o Tecircn matilde Cupcake

o Phiecircn b n Linux kernel 2627ả

o Tiacutenh năng

+ Cupcake mang nhi u tiacutenh năng m i nh bagraven phiacutem o coacute khề ớ ư ả ả

năng d đoaacuten t đang gotilde t đi n t ng do ng i dugraveng đ tự ừ ừ ể ừ ữ ườ ặ

ra h tr widget trecircn giao di n quay phim vagrave phaacutet l i videoỗ ợ ệ ạ

clip l c s th i gian cu c g i ch đ t đ ng xoay magravenượ ử ờ ộ ọ ế ộ ự ộ

higravenh theo h ng s d ng Trigravenh duy t web trong Cupcake coacuteướ ử ụ ệ

thecircm kh năng sao copypasteả

Phiecircn b n 1ả 6

o Ngagravey cocircng b ố 30-9-2009

o Tecircn matilde Donut

o Phiecircn b n Linux kernel 2629ả

o Tiacutenh năng

+ Cung c p ch c nan g tigravem ki m nhanh đ c văn b nấ ứ ư ế ọ ả xoacutea

nhi u file nh cugraveng luacutec ề ả

Phiecircn b n ả 20

o Ngagravey cocircng b ố 26-10-2009

o Tecircn matilde Eacuteclair

o Phiecircn b n Linux kernel 2629ả

o Tiacutenh năng

+ Cho pheacutep qu n lyacute nhi u tagravei kho n Email tigravem ki m tin nh nả ề ả ế ắ

Tigravem ki m b ng gi ng noacutei Google map H ng đ n caacutec thế ằ ọ ướ ế ế

h smartphone magraven higravenh l nệ ớ

Phiecircn b n ả 22

o Ngagravey cocircng b ố 20-5-2010

o Tecircn matilde Froyo

o Phiecircn b n Linux kernel 2632ả

o Tiacutenh năng

+ H tr Flash cho pheacutep bi n chi c smartphone thagravenh thi t bỗ ợ ế ế ế ị

phaacutet soacuteng Wi-Fi cho pheacutep cagravei đ t ng d ng lecircn th nh SDặ ứ ụ ẻ ớ

thay vigrave m c đ nh cagravei ngay vagraveo b nh trong c a thi t b m tặ ị ộ ớ ủ ế ị ậ

kh u đatilde h tr s vagrave ch s ẩ ỗ ợ ố ữ ố

Phiecircn b n ả 23

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Gingerbread

o Phiecircn b n Linux kernel 2635ả

o Tiacutenh năng

+ H tr thi t k giao di n đ n gi n vagrave hi u qu Nh p vănỗ ợ ế ế ệ ơ ả ệ ả ậ

b n thocircng minh vagrave nhanh h n h tr ch c năng copy vagrave daacutenả ơ ỗ ợ ứ

h tr tiacutenh năng d n raacutecỗ ợ ọ Đ n cu i năm 2012 Gingerbreadế ố

v n đang ph soacuteng trecircn r t nhi u thi t b dugraveng Androidẫ ủ ấ ề ế ị

chi m đ n h n phacircn n a (54)ế ế ơ ử

Phiecircn b n ả 30

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Honeycomb

o Phiecircn b n Linux kernel 2636ả

o Tiacutenh năng

+ Đacircy coacute th xem lagrave m t th h Android đ u tiecircn dagravenh riecircngể ộ ế ệ ầ

cho maacutey tiacutenh b ng (tablet)ả Android 30 c i ti n giao di n phugraveả ế ệ

h p v i caacutech s d ng maacutey tiacutenh b ng bagraven phiacutem o thacircn thi nợ ớ ử ụ ả ả ệ

h n h tr x lyacute đa taacutec v (multi-tasking) cho pheacutep chuy nơ ỗ ợ ử ụ ể

đ i qua l i caacutec ng d ng đang cugraveng ch y Ph n lotildei h th ngổ ạ ứ ụ ạ ầ ệ ố

coacute caacutec c i ti n t ng thiacutech v i ph n c ng nh h tr chip xả ế ươ ớ ầ ứ ư ỗ ợ ử

lyacute (CPU) đa lotildei tăng t c ph n c ngố ầ ứ

Phiecircn b n ả 40

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Ice Cream Sandwich

o Phiecircn b n Linux kernel 301ả

o Tiacutenh năng

+ Đacircy lagrave s k t h p c a phiecircn b n 3x cho maacutey tiacutenh b ng vagraveự ế ợ ủ ả ả

2x cho đi n tho i di đ ng Phiecircnb n nagravey coacute caacutec tiacutenh năng uệ ạ ộ ả ư

vi t nh giao di n đ p h n widget coacute th thay đ i kiacutechệ ư ệ ẹ ơ ể ổ

th c cho pheacutep khoacutea magraven higravenh ướ

Phiecircn b n ả m i nh t 42 ớ ấ

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Jelly Bean

o Phiecircn b n Linux kernel 34ả

o Tiacutenh năng

+ Android 42 ti p t c mang đ n nh ng c i ti n h p d n choế ụ ế ữ ả ế ấ ẫ

ng d ng ch p nh (Camera) nh ứ ụ ụ ả ư ch p nh trung th c HDRụ ả ự

(High Dynamic Range) ch o nh r ng Photo Sphere hi uụ ả ộ ệ

ng nh tigravem ki m thocircng minh vagrave đ p h n Google Now đ aứ ả ế ẹ ơ ư

tiacutenh năng l t ch n t r t hay trong bagraven phiacutem o Ch c năngướ ọ ừ ấ ả ứ

h tr nhi u tagravei kho n ng i dugraveng (multi-user profile) l nỗ ợ ề ả ườ ầ

đ u tiecircn đ c aacutep d ng trong Android 42 nh ng ch coacute ng iầ ượ ụ ư ỉ ườ

dugraveng maacutey tiacutenh b ng th a h ng ch c năng nagraveyả ừ ưở ứ

Đ n cu i năm 2012ế ố v n cograven đ n 54 thi t b Android dugraveng Gingerbreadẫ ế ế ị

(Android 23) Ice Cream Sandwich (Android 40) theo sau v i 258 Th hớ ế ệ

Jelly Bean m i nh t cograven khaacute iacutet i v i 27 thi t b s d ngớ ấ ỏ ớ ế ị ử ụ

113 u vagrave nh c đi m c a AndroidƯ ượ ể ủ

Vigrave Android lagrave h đi u hagravenh matilde ngu n mệ ề ồ ở necircn coacute nh ng u vagrave nh c đi mữ ư ượ ể

sau

1131 u đi mƯ ể

An ninh Caacutec l i nhanh choacuteng đ c phaacutet hi n vagrave s a đ iỗ ượ ệ ử ổ

Ch t l ngấ ượ Caacutec ng d ng khocircng ng ng đ c c i ti n phugrave h p v i nhuứ ụ ừ ượ ả ế ợ ớ

c u s d ng c a nhi u ng iầ ử ụ ủ ề ườ

Kh năng tugravey bi nả ế Nh ng đo n matilde trong ch ng trigraven đ c cocircng khaiữ ạ ươ ượ

necircn ng i dugraveng coacute th thecircm b t caacutec ch c năng tuacutey yacute mu nườ ể ớ ứ ố

Chi phiacute S d ng s n ph m matilde ngu n m hoagraven toagraven khocircng t n phiacute ti tử ụ ả ẩ ồ ở ố ế

ki m kinh phiacuteệ

1132 Nh c đi mượ ể

Kh năng b o m t ả ả ậ Vigrave Android lagrave h đi u hagravenh matilde ngu n m necircn t tệ ề ồ ở ấ

c caacutec thocircng tin v h th ng m i ng i đ u n m đ c Đacircy lagrave u đi mả ề ệ ố ọ ườ ề ắ ượ ư ể

vagrave cũng lagrave nh c đi m b i vigrave caacutec hacker coacute th tigravem ki m nh ng l h ngượ ể ở ể ế ữ ỗ ổ

h th ng vagrave t o ra nh ng matilde đ cệ ố ạ ữ ộ

114 N n t ng h đi u hagravenh Androidề ả ệ ề

httpsdocsgooglecomdocumentpreview

hgd=1ampid=1ehWmLcA4DmeQ2GDYqzBvUyby3BwdUHRMuaP_6tX7dOMamppli=1

1141 Caacutec thagravenh ph n c a Androidầ ủ

L c đ sau th hi n caacutec thagravenh ph n c a h đi u hagravenh Androidượ ồ ể ệ ầ ủ ệ ề

Coacute 5 t ng phacircn bi t trong h th ng Androidầ ệ ệ ố

Applications

H đi u hagravenh Android tiacutech h p s n m t s ng d ng c b n nh emailệ ề ợ ẳ ộ ố ứ ụ ơ ả ư

client SMS l ch đi n t b n đ trigravenh duy t web s liecircn l c vagrave m t s ngị ệ ử ả ồ ệ ổ ạ ộ ố ứ

d ng khaacutec Ngoagravei ra t ng nagravey cũng chiacutenh lagrave t ng ch a caacutec ng d ng đ c phaacutetụ ầ ầ ứ ứ ụ ượ

tri n b ng ngocircn ng Javaể ằ ữ

Application Framework

Trong t ng nagravey thagravenh ph n quan tr ng nh t lagrave Acitivity Manager vigrave noacute qu nầ ầ ọ ấ ả

lyacute vograveng đ i c a m t Activityờ ủ ộ

T ng nagravey ch a caacutec th vi n Java h tr ng i dugraveng giao ti p v i t ngầ ứ ư ệ ỗ ợ ườ ế ớ ầ

Android Framework M t ph n c a th vi n nagravey do Google cung c p s n m tộ ầ ủ ư ệ ấ ẵ ộ

ph n do ta t o ra Nh v y caacutec nhagrave phaacutet tri n ng d ng coacute kh năng t o ra caacutecầ ạ ờ ậ ể ứ ụ ả ạ

ng d ng vocirc cugraveng saacuteng t o vagrave phong phuacute Caacutec nhagrave phaacutet tri n ng d ng đ c tứ ụ ạ ể ứ ụ ượ ự

do s d ng caacutec tiacutenh năng cao c p c a thi t b ph n c ng nh thocircng tin đ nh vử ụ ấ ủ ế ị ầ ứ ư ị ị

APPLICATIONS

Home Contacts Phone Browser hellip

Home

APPLICATION FRAMEWORK

Activity Manager Windows Manager Content Provider View System Package Manager

Telephony Manager Resource Manager Location Manager Notification Manager

Home

LIBRARIES

Surface Manager Media Framework SQLite

OpenGL | ES Free Type Webkit

SGL SSL libc

ANDROID RUNTIME

Core Libraries

Davik Virtual Machine

Home

LINUX KERNEL

Display Driver Camera Driver Flash Memory Driver Binder (IPC) Driver

KeyPad Driver Wifi Driver Audi Driver Power Management

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 3: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Internet Tivi Smart TV

112 Caacutec phiecircn b n Androidả

(Tham kh o ngu n ả ồ httpenwikipediaorgwikiAndroid_version_history

httpnhipsongsotuoitrevnKien-thuc-Cong-nghe519360Luoc-su-Android-qua-

cac-phien-banhtml)

Phiecircn b n 10 ả

o Ngagravey cocircng b ố 23-11-2008

o Tecircn matilde Astro Boy hay Bender

o Phiecircn b n Linux kernel 2625ả

o Tiacutenh năng

+ Android 10 r t nguyecircn s tiacutech h p s n kh năng đ ng bấ ơ ợ ẵ ả ồ ộ

d li u v i caacutec d ch v tr c tuy n c a Google nh Gmailữ ệ ớ ị ụ ự ế ủ ư

Google Calendar vagrave Contacts m t trigravenh phaacutet media h trộ ỗ ợ

Wi-Fi vagrave Bluetooth thanh tr ng thaacutei hi n th caacutec thocircng baacuteoạ ể ị

ng d ng vagrave m t ng d ng ch p nh (camera) tuy ch a choứ ụ ộ ứ ụ ụ ả ư

pheacutep thay đ i đ phacircn gi i vagrave ch t l ng nhổ ộ ả ấ ượ ả

Phiecircn b n 1ả 5

o Ngagravey cocircng b ố 30-4-2009

o Tecircn matilde Cupcake

o Phiecircn b n Linux kernel 2627ả

o Tiacutenh năng

+ Cupcake mang nhi u tiacutenh năng m i nh bagraven phiacutem o coacute khề ớ ư ả ả

năng d đoaacuten t đang gotilde t đi n t ng do ng i dugraveng đ tự ừ ừ ể ừ ữ ườ ặ

ra h tr widget trecircn giao di n quay phim vagrave phaacutet l i videoỗ ợ ệ ạ

clip l c s th i gian cu c g i ch đ t đ ng xoay magravenượ ử ờ ộ ọ ế ộ ự ộ

higravenh theo h ng s d ng Trigravenh duy t web trong Cupcake coacuteướ ử ụ ệ

thecircm kh năng sao copypasteả

Phiecircn b n 1ả 6

o Ngagravey cocircng b ố 30-9-2009

o Tecircn matilde Donut

o Phiecircn b n Linux kernel 2629ả

o Tiacutenh năng

+ Cung c p ch c nan g tigravem ki m nhanh đ c văn b nấ ứ ư ế ọ ả xoacutea

nhi u file nh cugraveng luacutec ề ả

Phiecircn b n ả 20

o Ngagravey cocircng b ố 26-10-2009

o Tecircn matilde Eacuteclair

o Phiecircn b n Linux kernel 2629ả

o Tiacutenh năng

+ Cho pheacutep qu n lyacute nhi u tagravei kho n Email tigravem ki m tin nh nả ề ả ế ắ

Tigravem ki m b ng gi ng noacutei Google map H ng đ n caacutec thế ằ ọ ướ ế ế

h smartphone magraven higravenh l nệ ớ

Phiecircn b n ả 22

o Ngagravey cocircng b ố 20-5-2010

o Tecircn matilde Froyo

o Phiecircn b n Linux kernel 2632ả

o Tiacutenh năng

+ H tr Flash cho pheacutep bi n chi c smartphone thagravenh thi t bỗ ợ ế ế ế ị

phaacutet soacuteng Wi-Fi cho pheacutep cagravei đ t ng d ng lecircn th nh SDặ ứ ụ ẻ ớ

thay vigrave m c đ nh cagravei ngay vagraveo b nh trong c a thi t b m tặ ị ộ ớ ủ ế ị ậ

kh u đatilde h tr s vagrave ch s ẩ ỗ ợ ố ữ ố

Phiecircn b n ả 23

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Gingerbread

o Phiecircn b n Linux kernel 2635ả

o Tiacutenh năng

+ H tr thi t k giao di n đ n gi n vagrave hi u qu Nh p vănỗ ợ ế ế ệ ơ ả ệ ả ậ

b n thocircng minh vagrave nhanh h n h tr ch c năng copy vagrave daacutenả ơ ỗ ợ ứ

h tr tiacutenh năng d n raacutecỗ ợ ọ Đ n cu i năm 2012 Gingerbreadế ố

v n đang ph soacuteng trecircn r t nhi u thi t b dugraveng Androidẫ ủ ấ ề ế ị

chi m đ n h n phacircn n a (54)ế ế ơ ử

Phiecircn b n ả 30

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Honeycomb

o Phiecircn b n Linux kernel 2636ả

o Tiacutenh năng

+ Đacircy coacute th xem lagrave m t th h Android đ u tiecircn dagravenh riecircngể ộ ế ệ ầ

cho maacutey tiacutenh b ng (tablet)ả Android 30 c i ti n giao di n phugraveả ế ệ

h p v i caacutech s d ng maacutey tiacutenh b ng bagraven phiacutem o thacircn thi nợ ớ ử ụ ả ả ệ

h n h tr x lyacute đa taacutec v (multi-tasking) cho pheacutep chuy nơ ỗ ợ ử ụ ể

đ i qua l i caacutec ng d ng đang cugraveng ch y Ph n lotildei h th ngổ ạ ứ ụ ạ ầ ệ ố

coacute caacutec c i ti n t ng thiacutech v i ph n c ng nh h tr chip xả ế ươ ớ ầ ứ ư ỗ ợ ử

lyacute (CPU) đa lotildei tăng t c ph n c ngố ầ ứ

Phiecircn b n ả 40

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Ice Cream Sandwich

o Phiecircn b n Linux kernel 301ả

o Tiacutenh năng

+ Đacircy lagrave s k t h p c a phiecircn b n 3x cho maacutey tiacutenh b ng vagraveự ế ợ ủ ả ả

2x cho đi n tho i di đ ng Phiecircnb n nagravey coacute caacutec tiacutenh năng uệ ạ ộ ả ư

vi t nh giao di n đ p h n widget coacute th thay đ i kiacutechệ ư ệ ẹ ơ ể ổ

th c cho pheacutep khoacutea magraven higravenh ướ

Phiecircn b n ả m i nh t 42 ớ ấ

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Jelly Bean

o Phiecircn b n Linux kernel 34ả

o Tiacutenh năng

+ Android 42 ti p t c mang đ n nh ng c i ti n h p d n choế ụ ế ữ ả ế ấ ẫ

ng d ng ch p nh (Camera) nh ứ ụ ụ ả ư ch p nh trung th c HDRụ ả ự

(High Dynamic Range) ch o nh r ng Photo Sphere hi uụ ả ộ ệ

ng nh tigravem ki m thocircng minh vagrave đ p h n Google Now đ aứ ả ế ẹ ơ ư

tiacutenh năng l t ch n t r t hay trong bagraven phiacutem o Ch c năngướ ọ ừ ấ ả ứ

h tr nhi u tagravei kho n ng i dugraveng (multi-user profile) l nỗ ợ ề ả ườ ầ

đ u tiecircn đ c aacutep d ng trong Android 42 nh ng ch coacute ng iầ ượ ụ ư ỉ ườ

dugraveng maacutey tiacutenh b ng th a h ng ch c năng nagraveyả ừ ưở ứ

Đ n cu i năm 2012ế ố v n cograven đ n 54 thi t b Android dugraveng Gingerbreadẫ ế ế ị

(Android 23) Ice Cream Sandwich (Android 40) theo sau v i 258 Th hớ ế ệ

Jelly Bean m i nh t cograven khaacute iacutet i v i 27 thi t b s d ngớ ấ ỏ ớ ế ị ử ụ

113 u vagrave nh c đi m c a AndroidƯ ượ ể ủ

Vigrave Android lagrave h đi u hagravenh matilde ngu n mệ ề ồ ở necircn coacute nh ng u vagrave nh c đi mữ ư ượ ể

sau

1131 u đi mƯ ể

An ninh Caacutec l i nhanh choacuteng đ c phaacutet hi n vagrave s a đ iỗ ượ ệ ử ổ

Ch t l ngấ ượ Caacutec ng d ng khocircng ng ng đ c c i ti n phugrave h p v i nhuứ ụ ừ ượ ả ế ợ ớ

c u s d ng c a nhi u ng iầ ử ụ ủ ề ườ

Kh năng tugravey bi nả ế Nh ng đo n matilde trong ch ng trigraven đ c cocircng khaiữ ạ ươ ượ

necircn ng i dugraveng coacute th thecircm b t caacutec ch c năng tuacutey yacute mu nườ ể ớ ứ ố

Chi phiacute S d ng s n ph m matilde ngu n m hoagraven toagraven khocircng t n phiacute ti tử ụ ả ẩ ồ ở ố ế

ki m kinh phiacuteệ

1132 Nh c đi mượ ể

Kh năng b o m t ả ả ậ Vigrave Android lagrave h đi u hagravenh matilde ngu n m necircn t tệ ề ồ ở ấ

c caacutec thocircng tin v h th ng m i ng i đ u n m đ c Đacircy lagrave u đi mả ề ệ ố ọ ườ ề ắ ượ ư ể

vagrave cũng lagrave nh c đi m b i vigrave caacutec hacker coacute th tigravem ki m nh ng l h ngượ ể ở ể ế ữ ỗ ổ

h th ng vagrave t o ra nh ng matilde đ cệ ố ạ ữ ộ

114 N n t ng h đi u hagravenh Androidề ả ệ ề

httpsdocsgooglecomdocumentpreview

hgd=1ampid=1ehWmLcA4DmeQ2GDYqzBvUyby3BwdUHRMuaP_6tX7dOMamppli=1

1141 Caacutec thagravenh ph n c a Androidầ ủ

L c đ sau th hi n caacutec thagravenh ph n c a h đi u hagravenh Androidượ ồ ể ệ ầ ủ ệ ề

Coacute 5 t ng phacircn bi t trong h th ng Androidầ ệ ệ ố

Applications

H đi u hagravenh Android tiacutech h p s n m t s ng d ng c b n nh emailệ ề ợ ẳ ộ ố ứ ụ ơ ả ư

client SMS l ch đi n t b n đ trigravenh duy t web s liecircn l c vagrave m t s ngị ệ ử ả ồ ệ ổ ạ ộ ố ứ

d ng khaacutec Ngoagravei ra t ng nagravey cũng chiacutenh lagrave t ng ch a caacutec ng d ng đ c phaacutetụ ầ ầ ứ ứ ụ ượ

tri n b ng ngocircn ng Javaể ằ ữ

Application Framework

Trong t ng nagravey thagravenh ph n quan tr ng nh t lagrave Acitivity Manager vigrave noacute qu nầ ầ ọ ấ ả

lyacute vograveng đ i c a m t Activityờ ủ ộ

T ng nagravey ch a caacutec th vi n Java h tr ng i dugraveng giao ti p v i t ngầ ứ ư ệ ỗ ợ ườ ế ớ ầ

Android Framework M t ph n c a th vi n nagravey do Google cung c p s n m tộ ầ ủ ư ệ ấ ẵ ộ

ph n do ta t o ra Nh v y caacutec nhagrave phaacutet tri n ng d ng coacute kh năng t o ra caacutecầ ạ ờ ậ ể ứ ụ ả ạ

ng d ng vocirc cugraveng saacuteng t o vagrave phong phuacute Caacutec nhagrave phaacutet tri n ng d ng đ c tứ ụ ạ ể ứ ụ ượ ự

do s d ng caacutec tiacutenh năng cao c p c a thi t b ph n c ng nh thocircng tin đ nh vử ụ ấ ủ ế ị ầ ứ ư ị ị

APPLICATIONS

Home Contacts Phone Browser hellip

Home

APPLICATION FRAMEWORK

Activity Manager Windows Manager Content Provider View System Package Manager

Telephony Manager Resource Manager Location Manager Notification Manager

Home

LIBRARIES

Surface Manager Media Framework SQLite

OpenGL | ES Free Type Webkit

SGL SSL libc

ANDROID RUNTIME

Core Libraries

Davik Virtual Machine

Home

LINUX KERNEL

Display Driver Camera Driver Flash Memory Driver Binder (IPC) Driver

KeyPad Driver Wifi Driver Audi Driver Power Management

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 4: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Phiecircn b n ả 20

o Ngagravey cocircng b ố 26-10-2009

o Tecircn matilde Eacuteclair

o Phiecircn b n Linux kernel 2629ả

o Tiacutenh năng

+ Cho pheacutep qu n lyacute nhi u tagravei kho n Email tigravem ki m tin nh nả ề ả ế ắ

Tigravem ki m b ng gi ng noacutei Google map H ng đ n caacutec thế ằ ọ ướ ế ế

h smartphone magraven higravenh l nệ ớ

Phiecircn b n ả 22

o Ngagravey cocircng b ố 20-5-2010

o Tecircn matilde Froyo

o Phiecircn b n Linux kernel 2632ả

o Tiacutenh năng

+ H tr Flash cho pheacutep bi n chi c smartphone thagravenh thi t bỗ ợ ế ế ế ị

phaacutet soacuteng Wi-Fi cho pheacutep cagravei đ t ng d ng lecircn th nh SDặ ứ ụ ẻ ớ

thay vigrave m c đ nh cagravei ngay vagraveo b nh trong c a thi t b m tặ ị ộ ớ ủ ế ị ậ

kh u đatilde h tr s vagrave ch s ẩ ỗ ợ ố ữ ố

Phiecircn b n ả 23

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Gingerbread

o Phiecircn b n Linux kernel 2635ả

o Tiacutenh năng

+ H tr thi t k giao di n đ n gi n vagrave hi u qu Nh p vănỗ ợ ế ế ệ ơ ả ệ ả ậ

b n thocircng minh vagrave nhanh h n h tr ch c năng copy vagrave daacutenả ơ ỗ ợ ứ

h tr tiacutenh năng d n raacutecỗ ợ ọ Đ n cu i năm 2012 Gingerbreadế ố

v n đang ph soacuteng trecircn r t nhi u thi t b dugraveng Androidẫ ủ ấ ề ế ị

chi m đ n h n phacircn n a (54)ế ế ơ ử

Phiecircn b n ả 30

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Honeycomb

o Phiecircn b n Linux kernel 2636ả

o Tiacutenh năng

+ Đacircy coacute th xem lagrave m t th h Android đ u tiecircn dagravenh riecircngể ộ ế ệ ầ

cho maacutey tiacutenh b ng (tablet)ả Android 30 c i ti n giao di n phugraveả ế ệ

h p v i caacutech s d ng maacutey tiacutenh b ng bagraven phiacutem o thacircn thi nợ ớ ử ụ ả ả ệ

h n h tr x lyacute đa taacutec v (multi-tasking) cho pheacutep chuy nơ ỗ ợ ử ụ ể

đ i qua l i caacutec ng d ng đang cugraveng ch y Ph n lotildei h th ngổ ạ ứ ụ ạ ầ ệ ố

coacute caacutec c i ti n t ng thiacutech v i ph n c ng nh h tr chip xả ế ươ ớ ầ ứ ư ỗ ợ ử

lyacute (CPU) đa lotildei tăng t c ph n c ngố ầ ứ

Phiecircn b n ả 40

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Ice Cream Sandwich

o Phiecircn b n Linux kernel 301ả

o Tiacutenh năng

+ Đacircy lagrave s k t h p c a phiecircn b n 3x cho maacutey tiacutenh b ng vagraveự ế ợ ủ ả ả

2x cho đi n tho i di đ ng Phiecircnb n nagravey coacute caacutec tiacutenh năng uệ ạ ộ ả ư

vi t nh giao di n đ p h n widget coacute th thay đ i kiacutechệ ư ệ ẹ ơ ể ổ

th c cho pheacutep khoacutea magraven higravenh ướ

Phiecircn b n ả m i nh t 42 ớ ấ

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Jelly Bean

o Phiecircn b n Linux kernel 34ả

o Tiacutenh năng

+ Android 42 ti p t c mang đ n nh ng c i ti n h p d n choế ụ ế ữ ả ế ấ ẫ

ng d ng ch p nh (Camera) nh ứ ụ ụ ả ư ch p nh trung th c HDRụ ả ự

(High Dynamic Range) ch o nh r ng Photo Sphere hi uụ ả ộ ệ

ng nh tigravem ki m thocircng minh vagrave đ p h n Google Now đ aứ ả ế ẹ ơ ư

tiacutenh năng l t ch n t r t hay trong bagraven phiacutem o Ch c năngướ ọ ừ ấ ả ứ

h tr nhi u tagravei kho n ng i dugraveng (multi-user profile) l nỗ ợ ề ả ườ ầ

đ u tiecircn đ c aacutep d ng trong Android 42 nh ng ch coacute ng iầ ượ ụ ư ỉ ườ

dugraveng maacutey tiacutenh b ng th a h ng ch c năng nagraveyả ừ ưở ứ

Đ n cu i năm 2012ế ố v n cograven đ n 54 thi t b Android dugraveng Gingerbreadẫ ế ế ị

(Android 23) Ice Cream Sandwich (Android 40) theo sau v i 258 Th hớ ế ệ

Jelly Bean m i nh t cograven khaacute iacutet i v i 27 thi t b s d ngớ ấ ỏ ớ ế ị ử ụ

113 u vagrave nh c đi m c a AndroidƯ ượ ể ủ

Vigrave Android lagrave h đi u hagravenh matilde ngu n mệ ề ồ ở necircn coacute nh ng u vagrave nh c đi mữ ư ượ ể

sau

1131 u đi mƯ ể

An ninh Caacutec l i nhanh choacuteng đ c phaacutet hi n vagrave s a đ iỗ ượ ệ ử ổ

Ch t l ngấ ượ Caacutec ng d ng khocircng ng ng đ c c i ti n phugrave h p v i nhuứ ụ ừ ượ ả ế ợ ớ

c u s d ng c a nhi u ng iầ ử ụ ủ ề ườ

Kh năng tugravey bi nả ế Nh ng đo n matilde trong ch ng trigraven đ c cocircng khaiữ ạ ươ ượ

necircn ng i dugraveng coacute th thecircm b t caacutec ch c năng tuacutey yacute mu nườ ể ớ ứ ố

Chi phiacute S d ng s n ph m matilde ngu n m hoagraven toagraven khocircng t n phiacute ti tử ụ ả ẩ ồ ở ố ế

ki m kinh phiacuteệ

1132 Nh c đi mượ ể

Kh năng b o m t ả ả ậ Vigrave Android lagrave h đi u hagravenh matilde ngu n m necircn t tệ ề ồ ở ấ

c caacutec thocircng tin v h th ng m i ng i đ u n m đ c Đacircy lagrave u đi mả ề ệ ố ọ ườ ề ắ ượ ư ể

vagrave cũng lagrave nh c đi m b i vigrave caacutec hacker coacute th tigravem ki m nh ng l h ngượ ể ở ể ế ữ ỗ ổ

h th ng vagrave t o ra nh ng matilde đ cệ ố ạ ữ ộ

114 N n t ng h đi u hagravenh Androidề ả ệ ề

httpsdocsgooglecomdocumentpreview

hgd=1ampid=1ehWmLcA4DmeQ2GDYqzBvUyby3BwdUHRMuaP_6tX7dOMamppli=1

1141 Caacutec thagravenh ph n c a Androidầ ủ

L c đ sau th hi n caacutec thagravenh ph n c a h đi u hagravenh Androidượ ồ ể ệ ầ ủ ệ ề

Coacute 5 t ng phacircn bi t trong h th ng Androidầ ệ ệ ố

Applications

H đi u hagravenh Android tiacutech h p s n m t s ng d ng c b n nh emailệ ề ợ ẳ ộ ố ứ ụ ơ ả ư

client SMS l ch đi n t b n đ trigravenh duy t web s liecircn l c vagrave m t s ngị ệ ử ả ồ ệ ổ ạ ộ ố ứ

d ng khaacutec Ngoagravei ra t ng nagravey cũng chiacutenh lagrave t ng ch a caacutec ng d ng đ c phaacutetụ ầ ầ ứ ứ ụ ượ

tri n b ng ngocircn ng Javaể ằ ữ

Application Framework

Trong t ng nagravey thagravenh ph n quan tr ng nh t lagrave Acitivity Manager vigrave noacute qu nầ ầ ọ ấ ả

lyacute vograveng đ i c a m t Activityờ ủ ộ

T ng nagravey ch a caacutec th vi n Java h tr ng i dugraveng giao ti p v i t ngầ ứ ư ệ ỗ ợ ườ ế ớ ầ

Android Framework M t ph n c a th vi n nagravey do Google cung c p s n m tộ ầ ủ ư ệ ấ ẵ ộ

ph n do ta t o ra Nh v y caacutec nhagrave phaacutet tri n ng d ng coacute kh năng t o ra caacutecầ ạ ờ ậ ể ứ ụ ả ạ

ng d ng vocirc cugraveng saacuteng t o vagrave phong phuacute Caacutec nhagrave phaacutet tri n ng d ng đ c tứ ụ ạ ể ứ ụ ượ ự

do s d ng caacutec tiacutenh năng cao c p c a thi t b ph n c ng nh thocircng tin đ nh vử ụ ấ ủ ế ị ầ ứ ư ị ị

APPLICATIONS

Home Contacts Phone Browser hellip

Home

APPLICATION FRAMEWORK

Activity Manager Windows Manager Content Provider View System Package Manager

Telephony Manager Resource Manager Location Manager Notification Manager

Home

LIBRARIES

Surface Manager Media Framework SQLite

OpenGL | ES Free Type Webkit

SGL SSL libc

ANDROID RUNTIME

Core Libraries

Davik Virtual Machine

Home

LINUX KERNEL

Display Driver Camera Driver Flash Memory Driver Binder (IPC) Driver

KeyPad Driver Wifi Driver Audi Driver Power Management

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 5: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

h p v i caacutech s d ng maacutey tiacutenh b ng bagraven phiacutem o thacircn thi nợ ớ ử ụ ả ả ệ

h n h tr x lyacute đa taacutec v (multi-tasking) cho pheacutep chuy nơ ỗ ợ ử ụ ể

đ i qua l i caacutec ng d ng đang cugraveng ch y Ph n lotildei h th ngổ ạ ứ ụ ạ ầ ệ ố

coacute caacutec c i ti n t ng thiacutech v i ph n c ng nh h tr chip xả ế ươ ớ ầ ứ ư ỗ ợ ử

lyacute (CPU) đa lotildei tăng t c ph n c ngố ầ ứ

Phiecircn b n ả 40

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Ice Cream Sandwich

o Phiecircn b n Linux kernel 301ả

o Tiacutenh năng

+ Đacircy lagrave s k t h p c a phiecircn b n 3x cho maacutey tiacutenh b ng vagraveự ế ợ ủ ả ả

2x cho đi n tho i di đ ng Phiecircnb n nagravey coacute caacutec tiacutenh năng uệ ạ ộ ả ư

vi t nh giao di n đ p h n widget coacute th thay đ i kiacutechệ ư ệ ẹ ơ ể ổ

th c cho pheacutep khoacutea magraven higravenh ướ

Phiecircn b n ả m i nh t 42 ớ ấ

o Ngagravey cocircng b ố 6-12-2010

o Tecircn matilde Jelly Bean

o Phiecircn b n Linux kernel 34ả

o Tiacutenh năng

+ Android 42 ti p t c mang đ n nh ng c i ti n h p d n choế ụ ế ữ ả ế ấ ẫ

ng d ng ch p nh (Camera) nh ứ ụ ụ ả ư ch p nh trung th c HDRụ ả ự

(High Dynamic Range) ch o nh r ng Photo Sphere hi uụ ả ộ ệ

ng nh tigravem ki m thocircng minh vagrave đ p h n Google Now đ aứ ả ế ẹ ơ ư

tiacutenh năng l t ch n t r t hay trong bagraven phiacutem o Ch c năngướ ọ ừ ấ ả ứ

h tr nhi u tagravei kho n ng i dugraveng (multi-user profile) l nỗ ợ ề ả ườ ầ

đ u tiecircn đ c aacutep d ng trong Android 42 nh ng ch coacute ng iầ ượ ụ ư ỉ ườ

dugraveng maacutey tiacutenh b ng th a h ng ch c năng nagraveyả ừ ưở ứ

Đ n cu i năm 2012ế ố v n cograven đ n 54 thi t b Android dugraveng Gingerbreadẫ ế ế ị

(Android 23) Ice Cream Sandwich (Android 40) theo sau v i 258 Th hớ ế ệ

Jelly Bean m i nh t cograven khaacute iacutet i v i 27 thi t b s d ngớ ấ ỏ ớ ế ị ử ụ

113 u vagrave nh c đi m c a AndroidƯ ượ ể ủ

Vigrave Android lagrave h đi u hagravenh matilde ngu n mệ ề ồ ở necircn coacute nh ng u vagrave nh c đi mữ ư ượ ể

sau

1131 u đi mƯ ể

An ninh Caacutec l i nhanh choacuteng đ c phaacutet hi n vagrave s a đ iỗ ượ ệ ử ổ

Ch t l ngấ ượ Caacutec ng d ng khocircng ng ng đ c c i ti n phugrave h p v i nhuứ ụ ừ ượ ả ế ợ ớ

c u s d ng c a nhi u ng iầ ử ụ ủ ề ườ

Kh năng tugravey bi nả ế Nh ng đo n matilde trong ch ng trigraven đ c cocircng khaiữ ạ ươ ượ

necircn ng i dugraveng coacute th thecircm b t caacutec ch c năng tuacutey yacute mu nườ ể ớ ứ ố

Chi phiacute S d ng s n ph m matilde ngu n m hoagraven toagraven khocircng t n phiacute ti tử ụ ả ẩ ồ ở ố ế

ki m kinh phiacuteệ

1132 Nh c đi mượ ể

Kh năng b o m t ả ả ậ Vigrave Android lagrave h đi u hagravenh matilde ngu n m necircn t tệ ề ồ ở ấ

c caacutec thocircng tin v h th ng m i ng i đ u n m đ c Đacircy lagrave u đi mả ề ệ ố ọ ườ ề ắ ượ ư ể

vagrave cũng lagrave nh c đi m b i vigrave caacutec hacker coacute th tigravem ki m nh ng l h ngượ ể ở ể ế ữ ỗ ổ

h th ng vagrave t o ra nh ng matilde đ cệ ố ạ ữ ộ

114 N n t ng h đi u hagravenh Androidề ả ệ ề

httpsdocsgooglecomdocumentpreview

hgd=1ampid=1ehWmLcA4DmeQ2GDYqzBvUyby3BwdUHRMuaP_6tX7dOMamppli=1

1141 Caacutec thagravenh ph n c a Androidầ ủ

L c đ sau th hi n caacutec thagravenh ph n c a h đi u hagravenh Androidượ ồ ể ệ ầ ủ ệ ề

Coacute 5 t ng phacircn bi t trong h th ng Androidầ ệ ệ ố

Applications

H đi u hagravenh Android tiacutech h p s n m t s ng d ng c b n nh emailệ ề ợ ẳ ộ ố ứ ụ ơ ả ư

client SMS l ch đi n t b n đ trigravenh duy t web s liecircn l c vagrave m t s ngị ệ ử ả ồ ệ ổ ạ ộ ố ứ

d ng khaacutec Ngoagravei ra t ng nagravey cũng chiacutenh lagrave t ng ch a caacutec ng d ng đ c phaacutetụ ầ ầ ứ ứ ụ ượ

tri n b ng ngocircn ng Javaể ằ ữ

Application Framework

Trong t ng nagravey thagravenh ph n quan tr ng nh t lagrave Acitivity Manager vigrave noacute qu nầ ầ ọ ấ ả

lyacute vograveng đ i c a m t Activityờ ủ ộ

T ng nagravey ch a caacutec th vi n Java h tr ng i dugraveng giao ti p v i t ngầ ứ ư ệ ỗ ợ ườ ế ớ ầ

Android Framework M t ph n c a th vi n nagravey do Google cung c p s n m tộ ầ ủ ư ệ ấ ẵ ộ

ph n do ta t o ra Nh v y caacutec nhagrave phaacutet tri n ng d ng coacute kh năng t o ra caacutecầ ạ ờ ậ ể ứ ụ ả ạ

ng d ng vocirc cugraveng saacuteng t o vagrave phong phuacute Caacutec nhagrave phaacutet tri n ng d ng đ c tứ ụ ạ ể ứ ụ ượ ự

do s d ng caacutec tiacutenh năng cao c p c a thi t b ph n c ng nh thocircng tin đ nh vử ụ ấ ủ ế ị ầ ứ ư ị ị

APPLICATIONS

Home Contacts Phone Browser hellip

Home

APPLICATION FRAMEWORK

Activity Manager Windows Manager Content Provider View System Package Manager

Telephony Manager Resource Manager Location Manager Notification Manager

Home

LIBRARIES

Surface Manager Media Framework SQLite

OpenGL | ES Free Type Webkit

SGL SSL libc

ANDROID RUNTIME

Core Libraries

Davik Virtual Machine

Home

LINUX KERNEL

Display Driver Camera Driver Flash Memory Driver Binder (IPC) Driver

KeyPad Driver Wifi Driver Audi Driver Power Management

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 6: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

113 u vagrave nh c đi m c a AndroidƯ ượ ể ủ

Vigrave Android lagrave h đi u hagravenh matilde ngu n mệ ề ồ ở necircn coacute nh ng u vagrave nh c đi mữ ư ượ ể

sau

1131 u đi mƯ ể

An ninh Caacutec l i nhanh choacuteng đ c phaacutet hi n vagrave s a đ iỗ ượ ệ ử ổ

Ch t l ngấ ượ Caacutec ng d ng khocircng ng ng đ c c i ti n phugrave h p v i nhuứ ụ ừ ượ ả ế ợ ớ

c u s d ng c a nhi u ng iầ ử ụ ủ ề ườ

Kh năng tugravey bi nả ế Nh ng đo n matilde trong ch ng trigraven đ c cocircng khaiữ ạ ươ ượ

necircn ng i dugraveng coacute th thecircm b t caacutec ch c năng tuacutey yacute mu nườ ể ớ ứ ố

Chi phiacute S d ng s n ph m matilde ngu n m hoagraven toagraven khocircng t n phiacute ti tử ụ ả ẩ ồ ở ố ế

ki m kinh phiacuteệ

1132 Nh c đi mượ ể

Kh năng b o m t ả ả ậ Vigrave Android lagrave h đi u hagravenh matilde ngu n m necircn t tệ ề ồ ở ấ

c caacutec thocircng tin v h th ng m i ng i đ u n m đ c Đacircy lagrave u đi mả ề ệ ố ọ ườ ề ắ ượ ư ể

vagrave cũng lagrave nh c đi m b i vigrave caacutec hacker coacute th tigravem ki m nh ng l h ngượ ể ở ể ế ữ ỗ ổ

h th ng vagrave t o ra nh ng matilde đ cệ ố ạ ữ ộ

114 N n t ng h đi u hagravenh Androidề ả ệ ề

httpsdocsgooglecomdocumentpreview

hgd=1ampid=1ehWmLcA4DmeQ2GDYqzBvUyby3BwdUHRMuaP_6tX7dOMamppli=1

1141 Caacutec thagravenh ph n c a Androidầ ủ

L c đ sau th hi n caacutec thagravenh ph n c a h đi u hagravenh Androidượ ồ ể ệ ầ ủ ệ ề

Coacute 5 t ng phacircn bi t trong h th ng Androidầ ệ ệ ố

Applications

H đi u hagravenh Android tiacutech h p s n m t s ng d ng c b n nh emailệ ề ợ ẳ ộ ố ứ ụ ơ ả ư

client SMS l ch đi n t b n đ trigravenh duy t web s liecircn l c vagrave m t s ngị ệ ử ả ồ ệ ổ ạ ộ ố ứ

d ng khaacutec Ngoagravei ra t ng nagravey cũng chiacutenh lagrave t ng ch a caacutec ng d ng đ c phaacutetụ ầ ầ ứ ứ ụ ượ

tri n b ng ngocircn ng Javaể ằ ữ

Application Framework

Trong t ng nagravey thagravenh ph n quan tr ng nh t lagrave Acitivity Manager vigrave noacute qu nầ ầ ọ ấ ả

lyacute vograveng đ i c a m t Activityờ ủ ộ

T ng nagravey ch a caacutec th vi n Java h tr ng i dugraveng giao ti p v i t ngầ ứ ư ệ ỗ ợ ườ ế ớ ầ

Android Framework M t ph n c a th vi n nagravey do Google cung c p s n m tộ ầ ủ ư ệ ấ ẵ ộ

ph n do ta t o ra Nh v y caacutec nhagrave phaacutet tri n ng d ng coacute kh năng t o ra caacutecầ ạ ờ ậ ể ứ ụ ả ạ

ng d ng vocirc cugraveng saacuteng t o vagrave phong phuacute Caacutec nhagrave phaacutet tri n ng d ng đ c tứ ụ ạ ể ứ ụ ượ ự

do s d ng caacutec tiacutenh năng cao c p c a thi t b ph n c ng nh thocircng tin đ nh vử ụ ấ ủ ế ị ầ ứ ư ị ị

APPLICATIONS

Home Contacts Phone Browser hellip

Home

APPLICATION FRAMEWORK

Activity Manager Windows Manager Content Provider View System Package Manager

Telephony Manager Resource Manager Location Manager Notification Manager

Home

LIBRARIES

Surface Manager Media Framework SQLite

OpenGL | ES Free Type Webkit

SGL SSL libc

ANDROID RUNTIME

Core Libraries

Davik Virtual Machine

Home

LINUX KERNEL

Display Driver Camera Driver Flash Memory Driver Binder (IPC) Driver

KeyPad Driver Wifi Driver Audi Driver Power Management

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 7: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

1141 Caacutec thagravenh ph n c a Androidầ ủ

L c đ sau th hi n caacutec thagravenh ph n c a h đi u hagravenh Androidượ ồ ể ệ ầ ủ ệ ề

Coacute 5 t ng phacircn bi t trong h th ng Androidầ ệ ệ ố

Applications

H đi u hagravenh Android tiacutech h p s n m t s ng d ng c b n nh emailệ ề ợ ẳ ộ ố ứ ụ ơ ả ư

client SMS l ch đi n t b n đ trigravenh duy t web s liecircn l c vagrave m t s ngị ệ ử ả ồ ệ ổ ạ ộ ố ứ

d ng khaacutec Ngoagravei ra t ng nagravey cũng chiacutenh lagrave t ng ch a caacutec ng d ng đ c phaacutetụ ầ ầ ứ ứ ụ ượ

tri n b ng ngocircn ng Javaể ằ ữ

Application Framework

Trong t ng nagravey thagravenh ph n quan tr ng nh t lagrave Acitivity Manager vigrave noacute qu nầ ầ ọ ấ ả

lyacute vograveng đ i c a m t Activityờ ủ ộ

T ng nagravey ch a caacutec th vi n Java h tr ng i dugraveng giao ti p v i t ngầ ứ ư ệ ỗ ợ ườ ế ớ ầ

Android Framework M t ph n c a th vi n nagravey do Google cung c p s n m tộ ầ ủ ư ệ ấ ẵ ộ

ph n do ta t o ra Nh v y caacutec nhagrave phaacutet tri n ng d ng coacute kh năng t o ra caacutecầ ạ ờ ậ ể ứ ụ ả ạ

ng d ng vocirc cugraveng saacuteng t o vagrave phong phuacute Caacutec nhagrave phaacutet tri n ng d ng đ c tứ ụ ạ ể ứ ụ ượ ự

do s d ng caacutec tiacutenh năng cao c p c a thi t b ph n c ng nh thocircng tin đ nh vử ụ ấ ủ ế ị ầ ứ ư ị ị

APPLICATIONS

Home Contacts Phone Browser hellip

Home

APPLICATION FRAMEWORK

Activity Manager Windows Manager Content Provider View System Package Manager

Telephony Manager Resource Manager Location Manager Notification Manager

Home

LIBRARIES

Surface Manager Media Framework SQLite

OpenGL | ES Free Type Webkit

SGL SSL libc

ANDROID RUNTIME

Core Libraries

Davik Virtual Machine

Home

LINUX KERNEL

Display Driver Camera Driver Flash Memory Driver Binder (IPC) Driver

KeyPad Driver Wifi Driver Audi Driver Power Management

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 8: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

đ a lyacute kh năng ch y d ch v d i n n thi t l p đ ng h baacuteo th c thecircm chuacuteị ả ạ ị ụ ướ ề ế ậ ồ ồ ứ

thiacutech (notification) vagraveo thanh tr ng thaacutei (status bar) c a magraven higravenh thi t b hellipạ ủ ế ị

Ng i phaacutet tri n ng d ng đ c pheacutep s d ng đ y đ b API đ c dugravengườ ể ứ ụ ượ ử ụ ầ ủ ộ ượ

trong caacutec ng d ng tiacutech h p s n c a Android Ki n truacutec ng d ng c a Androidứ ụ ợ ẳ ủ ế ứ ụ ủ

đ c thi t k nh m m c điacutech đ n gi n hoacutea vi c taacutei s d ng caacutec thagravenh ph nượ ế ế ằ ụ ơ ả ệ ử ụ ầ

(component) Qua đoacute b t kigrave ng d ng nagraveo cũng coacute th cocircng b caacutec tiacutenh năng magraveấ ứ ụ ể ố

noacute mu n chia s cho caacutec ng d ng khaacutec (Viacute d ng d ng email mu n caacutec ngố ẻ ứ ụ ụ Ứ ụ ố ứ

d ng khaacutec coacute th s d ng tiacutenh năng g i mail c a noacute) ụ ể ử ụ ở ủ

T ng nagravey bao g m m t t p caacutec services vagrave thagravenh ph n sauầ ồ ộ ậ ầ

+ View System dugraveng đ xacircy d ng ng d ng coacute caacutec đ i t ng nh list gridể ự ứ ụ ố ượ ư

text box button vagrave th m chiacute lagrave m t trigravenh duy t web coacute th nhuacuteng vagraveo ngậ ộ ệ ể ứ

d ngụ

+ Content Provider Cho pheacutep caacutec ng d ng coacute th truy xu t d li u t caacutecứ ụ ể ấ ữ ệ ừ

ng d ng khaacutec ho c chia s d li u c a chuacutengứ ụ ặ ẽ ữ ệ ủ

+ Resource Manager Cung c p kh năng truy xu t caacutec tagravei nguyecircn non-codeấ ả ấ

nh higravenh nh ho c file layoutư ả ặ

+ Notification Manager Cung c p kh năng hi n th custom alert trecircn thanhấ ả ể ị

status bar

+ Activity Manager Đacircy lagrave thagravenh ph n quan tr ng nh t giuacutep ng d ngầ ọ ấ ứ ụ

qu n lyacute vograveng đ i c a m t Activityả ờ ủ ộ

+ Telephony Manager Cung c p th vi n đ truy xu t đ n caacutec d ch vấ ư ệ ể ấ ế ị ụ

đi n tho i cũng nh thocircng tin thuecirc baoệ ạ ư

+ Location Manager Cung c p th vi n h tr ng i dugraveng đ nh v viacute triacuteấ ư ệ ỗ ợ ườ ị ị

c a thi t b ủ ế ị

Libraries

+ System C library T p th vi n h th ng C|Cậ ư ệ ệ ố ++ chu n (libc) coacute th g iẩ ể ọ

thocircng qua giao di n Javaệ

+ Media FrameWork B th vi n h tr trigravenh di n vagrave ghi caacutec đ nh d ngộ ư ệ ỗ ợ ễ ị ạ

acircm thanh vagrave higravenh nh ph bi nả ổ ế

+ Surface manager Cho pheacutep t o caacutec c a s giao di nạ ử ổ ệ

+ OpenGL H tr xacircy d ng caacutec ng d ng đ h a 2D vagrave 3Dỗ ợ ự ứ ụ ồ ọ

+ SSL Cung c p ch c năng b o m t thi t b ấ ứ ả ậ ế ị

+ SGL Engine h tr đ h a 2Dỗ ợ ồ ọ

+ Free Type H tr caacutec Font Bitmap vagrave vectorỗ ợ

+ SQLite Cung c p b maacutey c s d li u đ c nhuacuteng trong thi t b ấ ộ ơ ở ữ ệ ượ ế ị

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 9: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

+ Webkit h tr hi n th n i dung websiteỗ ợ ể ị ộ

Android Runtime

H đi u hagravenh Android tiacutech h p s n m t t p h p caacutec th vi n c t lotildei cungệ ề ợ ẳ ộ ậ ợ ư ệ ố

c p h u h t caacutec ch c năng coacute s n trong caacutec th vi n lotildei c a ngocircn ng l p trigravenhấ ầ ế ứ ẵ ư ệ ủ ữ ậ

Java M i ng d ng c a Android ch y trecircn m t ti n trigravenh c a riecircng noacute cugraveng v iọ ứ ụ ủ ạ ộ ế ủ ớ

m t th hi n c a maacutey o Dalvik Maacutey o Dalvik th c t lagrave m t bi n th c aộ ể ệ ủ ả ả ự ế ộ ế ể ủ

maacutey o Java đ c s a đ i b sung caacutec cocircng ngh đ c tr ng c a thi t b di đ ngả ượ ử ổ ổ ệ ặ ư ủ ế ị ộ

Noacute đ c xacircy d ng v i m c điacutech lagravem cho caacutec thi t b di đ ng coacute th ch y nhi uượ ự ớ ụ ế ị ộ ể ạ ề

maacutey o m t caacutech hi u qu Tr c khi th c thi b t kigrave ng d ng Android nagraveoả ộ ệ ả ướ ự ấ ứ ụ

cũng đ c ượ chuy n đ i thagravenh file th c thi v i đ nh d ng neacuten Dalvik Executableể ổ ự ớ ị ạ

(dex) Đ nh d ng nagravey đ c thi t k đ phugrave h p v i caacutec thi t b h n ch v bị ạ ượ ế ế ể ợ ớ ế ị ạ ế ề ộ

nh cũng nh t c đ x lyacute Ngoagravei ra maacutey o Dalvik s d ng b nhacircn Linux đớ ư ố ộ ử ả ử ụ ộ ể

cung c p caacutec tiacutenh năng nh lu ng (thread) qu n lyacute b nh th p (low-levelấ ư ồ ả ộ ớ ấ

memory management)

Linux Kernel

H đi u hagravenh Android đ c xacircy d ng trecircn b nhacircn Linux 26 cho nh ngệ ề ượ ự ộ ữ

d ch v h th ng c t lotildei nh security memory management processị ụ ệ ố ố ư

management network stack driver model B nhacircn nagravey lagravem nhi m v nh m tộ ệ ụ ư ộ

l p trung gian k t n i ph n c ng thi t b vagrave ph n ng d ngớ ế ố ầ ứ ế ị ầ ứ ụ

D i đacircy lagrave mocirc hinh h p taacutec gi a maacutey o Dalvik vagrave Navite codeướ ợ ữ ả

Higravenh 3 - Mocirc higravenh h p taacutec gi a maacutey o Dalvik vagrave Navite codeợ ữ ả

JNI Java Native Interface (T ng t khaacutei ni m Application Programmingươ ự ệ

Interface)

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 10: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Java Native Interface lagrave m t b framework cho pheacutep matilde l nh vi t b ng Javaộ ộ ệ ế ằ

ch y trecircn maacutey o java coacute th g i ho c đ c g i b i m t ng d ng vi t b ngạ ả ể ọ ặ ượ ọ ở ộ ứ ụ ế ằ

native code ( ng d ng đ c vi t cho m t ph n c ng c th vagrave trecircn m t h đi uỨ ụ ượ ế ộ ầ ứ ụ ể ộ ệ ề

hagravenh c th ) ho c nh ng b th vi n vi t b ng C C++ ho c Assembly B ngụ ể ặ ữ ộ ư ệ ế ằ ặ ằ

caacutech s d ng JNI Android cho pheacutep caacutec ng d ng ch y trecircn maacutey o Dalvik coacuteử ụ ứ ụ ạ ả

th s d ng nh ng ph ng th c đ c vi t b ng caacutec ngocircn ng c p th p nh Cể ử ụ ữ ươ ứ ượ ế ằ ữ ấ ấ ư

C++ Assembly Qua đoacute caacutec nhagrave phaacutet tri n ng d ng coacute th xacircy d ng ng d ngể ứ ụ ể ự ứ ụ

d a trecircn caacutec b th vi n vi t b ng C C++ Assembly nh m tăng t c đ th c thiự ộ ư ệ ế ằ ằ ố ộ ự

c a ng d ng ho c s d ng nh ng tiacutenh năng m c th p magrave ngocircn ng Java khocircngủ ứ ụ ặ ử ụ ữ ứ ấ ữ

h tr Tuy nhiecircn ng i phaacutet tri n ng d ng c n ph i cacircn nh c s gia tăng đỗ ợ ườ ể ứ ụ ầ ả ắ ự ộ

ph c t p c a ng d ng khi quy t đ nh s d ng caacutec b th vi n nagraveyứ ạ ủ ứ ụ ế ị ử ụ ộ ư ệ

1142 K t n i m ng (xem tagravei li u L p trigravenh Android Nguy n Th Ng c Tuacute)ế ố ạ ệ ậ ễ ị ọ

1143 B o m t (xem Nguy n th Ng c Tuacute)ả ậ ễ ị ọ

Android lagrave m t h th ng đa ti n trigravenh trong đoacute m i ng d ng ch y trongộ ệ ố ế ỗ ứ ụ ạ

m t ti n trigravenh riecircng bi t M i ng d ng trong ộ ế ệ ỗ ứ ụ Android đ c gaacuten m t ID vagrave m cượ ộ ặ

đ nh m t ng d ng khocircng coacute b t c quy n h n gigrave taacutec đ ng đ n h đi u hagravenhị ộ ứ ụ ấ ứ ề ạ ộ ế ệ ề

ng i dugraveng ho c ng d ng khaacutec Vi c cho pheacutep trao đ i thocircng tin vagrave t ng taacutecườ ặ ứ ụ ệ ổ ươ

qua l i gi a caacutec ti n trigravenh vagrave ng d ng trong Android ph i đ c đ nh nghĩa tr cạ ữ ế ứ ụ ả ượ ị ướ

trong ng d ng đ khi cagravei đ t h đi u hagravenh s nh n di n đ c thocircng tin nagraveyứ ụ ể ặ ệ ề ẽ ậ ệ ượ

C ch b o m t vagrave ng d ng ơ ế ả ậ ứ ụ Android coacute th mocirc t b ng higravenh nh sauể ả ằ ả

Ho t đ ng trong thi t b Androidạ ộ ế ị

1144 T p tin DEX (xem Nguy n th Ng c Tuacute)ậ ễ ị ọ

H đi u hagravenh Linux 26ệ ề

B O M TẢ Ậ

Qu n lyacuteả

Ti n trigravenhế

Qu n lyacuteả

B nhộ ớ

Ngăn x p ếm ngạ

Qu n lyacute ảxu t nh pấ ậ

Qu n lyacute ảngu n ồ

năng l ngượ

Bluetooth Camera Audio Telephony Flash c m ngả ứ

Ph n c ng v t lyacuteầ ứ ậ

Ng i dugraveng Cườ

Maacutey o DALVIKả

ng d ng CỨ ụ

Ng i dugraveng Bườ

Maacutey o DALVIKả

ng d ng BỨ ụ

Ng i dugraveng Aườ

Maacutey o DALVIKả

ng d ng AỨ ụ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 11: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Trong mocirci tr ng Java chu n m i l p ch a matilde ngu n Java đ c biecircn d chườ ẩ ỗ ớ ứ ồ ượ ị

thagravenh caacutec t p tin class ch a matilde nh phacircn Maacutey o Java coacute th đ c đ c caacutec t pậ ứ ị ả ể ọ ượ ậ

tin class nagravey Caacutec t p tin class đ c đoacuteng goacutei thagravenh t p tin jarậ ượ ậ

Trong n n t ng Android matilde ngu n Java cũng đ c biecircn d ch thagravenh caacutec t pề ả ồ ượ ị ậ

tin class Maacutey o DALVIK khocircng đ c đ c caacutec t p tin class nagraveyả ọ ượ ậ Caacutec t p tinậ

class đ c t ch c thagravenh t p tin dex (Dalvik Executable) Maacutey o DALVIK sượ ổ ứ ậ ả ẽ

th c thi t p tin dex nagravey T p tin dex đ c đoacuteng goacutei thagravenh t p tin apk Ng iự ậ ậ ượ ậ ườ

dugraveng t i t p tin apk vagrave Android s cagravei đ t ng d ng lecircn maacutey t t p tin nagraveyả ậ ẽ ặ ứ ụ ừ ậ

Coacute th so saacutenh vagrave higravenh dung quaacute trigravenh biecircn d ch vagrave đoacuteng goacutei caacutec thagravenh ph nể ị ầ

trong m t d aacuten Java thocircng th ng vagrave d aacuten Android nh sauộ ự ườ ự ư

12 Caacutec nguyecircn t c nguyecircn t c l p trigravenh t o caacutec ng d ng trecircnắ ắ ậ ạ ứ ụ

Android

121 Nh ng gi i h n c a thi t b ữ ớ ạ ủ ế ị đi n tho i di đ ng ệ ạ ộ Khaacutec v i l p trigravenh t oớ ậ ạ

ng d ng trecircn maacutey tiacutenh thocircng th ng khi t o ng d ng trecircn đi n tho i di đ ngứ ụ ườ ạ ứ ụ ệ ạ ộ

chuacuteng ta c n chuacute yacute nh ng gi i h n c a noacuteầ ữ ớ ạ ủ

B nh gi i h nộ ớ ớ ạ

Kh năng x lyacute gi i h nả ử ớ ạ

Ngu n năng l ng gi i h nồ ượ ớ ạ

Bagraven phiacutem nh ho c iacutet phiacutem ỏ ặ

Cocircng ngh vagrave n n t ng khaacutec nhauệ ề ả

Kiacutech th c magraven higravenh beacuteướ

Giao di n ng i dugraveng đ n gi nệ ườ ơ ả

Băng thocircng gi i h nớ ạ

K t n i m ng khocircng n đ nhế ố ạ ổ ị

122 Caacutec yecircu c u đ phaacutet tri n ph n m m trecircn n n t ng ầ ể ể ầ ề ề ả Android

+ Ki n th c l p trigravenh Javaế ứ ậ Ngocircn ng Java s d ng trong Android khocircng ph iữ ử ụ ả

lagrave toagraven b th vi n J2EE (Java 2 Platform Enterprise Edition) magrave nh ng nhagrave phaacutetộ ư ệ ữ

tri n Java th ng s d ng magrave ch lagrave m t ph n nh đ c xem lagrave maacutey o Dalvikể ườ ử ụ ỉ ộ ầ ỏ ượ ả

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin jarậ

Caacutec t p tin Javaậ Caacutec t p tin Classậ T p tin dexậ T p tin apkậ

ng d ng Java thocircng th ngỨ ụ ườ

ng d ng AndroidỨ ụ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 12: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Vigrave v y ta ch quan tacircm đ n nh ng th vi n đ c dugraveng đ vi t caacutecậ ỉ ế ữ ư ệ ượ ể ế ng d ng diứ ụ

đ ngộ

+ Ki n th c v XMLế ứ ề Ngocircn ngữ XML đ c dugraveng đ đ nh nghĩa caacutec tagravei nguyecircnượ ể ị

cho ng d ng layout menu caacutec tr (values ) t p tin thocircng tin h th ngứ ụ ị ậ ệ ố

AndroidmanifestXML

+ Caacutec cocircng c vagrave mocirci tr ng phaacutet tri nụ ườ ể

JDK (Java Development Kit) JDK lagrave mocirci tr ng dugraveng đ vi t caacutec ngườ ể ế ứ

d ng Java JDK g m JRE (ụ ồ Java Runtime Environment) vagrave caacutec cocircng cụ

nh trigravenh biecircn d ch (javacexe) trigravenh th c thi matilde (javaexe)ư ị ự g l i thỡ ỗ ư

vi n ph n m m b gi l p đi n tho i ệ ầ ề ộ ả ậ ệ ạ

Eclipse Coacute nhi u mocirci tr ng phaacutet tri n tiacutech h p (IDE ndashIntegratedề ườ ể ợ

Development Environment) mi n phiacute cho Java nh Jgraph Oracleễ ư

JDeveloper JEdit NetBeans Trong tr ng h p Android IDE đ c đườ ợ ượ ề

ngh lagrave Eclipseị

Android SDK (Software Development Kit) SDK lagrave b cocircng c phaacutetộ ụ

tri n ng d ng Android S n ph m nagravey do Google xacircy d ng vagrave phaacutetể ứ ụ ả ẩ ự

hagravenh mi n phiacuteễ

ADT (Android Development Tools) B cocircng c m r ng tiacutenh năngộ ụ ở ộ

c a Eclipse g mủ ồ

o Dx (Dalvik Cross- Assembler) Dugraveng đ chuy n caacutec l p Javaể ể ớ

(đatilde biecircn d ch) thagravenh m t file nh phacircn (dex) ch y trecircn maacutey oị ộ ị ạ ả

Dalvik

o Aapt (Android Asset Packing Tool) Dugraveng đ đoacuteng goacutei (neacuten) caacutecể

t p tin d ng dex thagravenh file apk cho pheacutep ng i dugraveng t i vagraveậ ạ ườ ả

cagravei đ t trecircn thi t b ặ ế ị

o Adb (Android Debug Bridge) T o c u n i đ chuy n vagrave cagraveiạ ầ ố ể ể

đ t matilde ngu n c a ng d ng lecircn trigravenh gi l p (Emulator) ho cặ ồ ủ ứ ụ ả ậ ặ

thi t b Androidế ị

o Ddms (Dalvik Debug Monitor Service) Cung c p nh ng d chấ ữ ị

v nh qu n lyacute thocircng tin ti n trigravenh vagrave ngăn x p logcat ụ ư ả ế ế

123 Qui trigravenh cagravei đ t mocirci tr ng phaacutet tri n ng d ng Androidặ ườ ể ứ ụ

124 Qui trigravenh t o m t ng d ng Androidạ ộ ứ ụ

Cagravei đ t JDKặ Cagravei đ t Eclipseặ Cagravei đ tặAndroid SDK

B sungổADT cho Eclipse

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 13: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

B c 1ướ Ch y Eclipseạ

o Ch n d aacuten Android (Android Application Project)ọ ự

o Khai baacuteo tecircn ng d ng tecircn d aacuten tecircn goacutei (package) ch n phiecircnứ ụ ự ọ

b n Android (build SDK) phiecircn b n th p nh t (Minimum Requiredả ả ấ ấ

SDK) n i l u ng d ng (location)ơ ư ứ ụ

o Ch n higravenh bi u t ng (icon)ọ ể ượ

o T o Activity r ng (Blank Activity)ạ ỗ

B c 2ướ T mocirci tr ng Eclipse thi t l p maacutey o (Android Virtualừ ườ ế ậ ả

Device) t ng ng v i phiecircn b n SDK đatilde ch n b c 1 (n u ch a thi tươ ứ ớ ả ọ ở ướ ế ư ế

l p)ậ

o Ch y ch c năng AVD Manager trong menu Windowsạ ứ

o Khai baacuteo tecircn maacutey o (Name) phiecircn b n Android (Target) đả ả ộ

phacircn gi i magraven higravenh (Skin) ả

B c 3ướ Xacircy d ng ng d ng khai baacuteo tagravei nguyecircn (Resource) t o giao di nự ứ ụ ạ ệ

(Layout) t o caacutec thagravenh ph n ng d ng (Component) vi t matilde x lyacuteạ ầ ứ ụ ế ử

(class)

B c ướ 4 Ch y (run as) ki m tra ng d ng vagrave k t thuacutec (s n ph m lagrave fileạ ể ứ ụ ế ả ẩ

apk trong th m c bin c a ng d ng) N u l i quay l i b c 3ư ụ ủ ứ ụ ế ỗ ạ ướ

Coacute th mocirc t ể ả qui trigravenh b ng s đ sauằ ơ ồB t đ uắ ầ

Ch y Eclipseạ

T o ADVạ

Xacircy d ng ng d ng ự ứ ụ

Ch y ng ng d ng ạ ứ ứ ụ

Ki m traể

K t thuacutecế

T tố

Ch a ưt tố

Coacute ADV

Ch a ư

coacute

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 14: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

125 Caacutec thagravenh ph n c u thagravenh m t d aacuten Androidầ ấ ộ ự

B t kỳ m t ng d ng Android nagraveo cũng đ c c u thagravenh t 3 thagravenh ph nấ ộ ứ ụ ượ ấ ừ ầ

chiacutenh Application Components t p tin AndroidManifestXML Applicationậ

Resources

1251 Application Components Coacute 4 lo i Application Componentsạ

Activities M t Activity đ i di n cho m t c a s ch a giao di n ngộ ạ ệ ộ ử ổ ứ ệ ứ

d ng magrave ng i dugraveng coacute th t ng taacutec tr c ti p Trong m i Activityụ ườ ể ươ ự ế ỗ

ngoagravei vi c thi t l p giao di n noacute cograven ph i x lyacute nh ng t ng taacutec gi aệ ế ậ ệ ả ử ữ ươ ữ

ng i dugraveng v i giao di n nh s ki n touch click M i Activityườ ớ ệ ư ự ệ ỗ

đ c t o ra trong ng d ng s lagrave m t l p con k t th a (extends) tượ ạ ứ ụ ẽ ộ ớ ế ừ ừ

l p Activity c a n n t ng Android (ớ ủ ề ả androidappActivity)

Services Đacircy lagrave lo i Application Component ch y n n đ th c hi nạ ạ ề ể ự ệ

nh ng cocircng vi c liecircn t c vagrave keacuteo dagravei Service khocircng coacute giao di n M tữ ệ ụ ệ ộ

Service đ c t o ra trong ng d ng lagrave m t l p con k t th a t l pượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Service c a n n t ng Android (ủ ề ả androidappService)

Content Providers Đacircy lagrave thagravenh ph n dugraveng đ qu n lyacute m t t p caacutecầ ể ả ộ ậ

d li u chia s đ c D li u coacute th l u tr d i d ng t p tin c sữ ệ ẻ ượ ữ ệ ể ư ữ ướ ạ ậ ơ ở

d li u SQLite ho c trecircn trang web Thocircng qua Content Providerữ ệ ặ

nh ng ng d ng coacute th truy v n hay ch nh s a d li u n u Contentữ ứ ụ ể ấ ỉ ử ữ ệ ế

Providers cho pheacutep M t Content Provider đ c t o ra trong ng d ngộ ượ ạ ứ ụ

lagrave m t l p con k t th a t l p Content Provider c a n n t ng Androidộ ớ ế ừ ừ ớ ủ ề ả

(androidcontentContentProvider)

Broadcast Receivers Đacircy lagrave thagravenh ph n trong ng d ng dugraveng đ l ngầ ứ ụ ể ắ

nghe caacutec thocircng đi p (Broadcast) đ c g i đi t h th ng Viacute d hệ ượ ở ừ ệ ố ụ ệ

th ng thocircng baacuteo ngu n năng l ng trong maacutey g n c n ki t thigraveố ồ ượ ầ ạ ệ

Broadcast Receivers s l ng nghe vagrave nh n thocircng đi p nagravey đ coacute nh ngẽ ắ ậ ệ ể ữ

ng x thiacutech h p B n thacircn m t ng d ng cũng coacute th g i đi nh ngứ ử ợ ả ộ ứ ụ ể ở ữ

thocircng đi p đ nh ng ng d ng khaacutec bi t M t Broadcast Receiversệ ể ữ ứ ụ ế ộ

đ c t o ra trong ng d ng lagrave m t l p con k t th a t l p Broadcastượ ạ ứ ụ ộ ớ ế ừ ừ ớ

Receivers c a n n t ng Android (ủ ề ả androidcontentBroadcastReceiver)

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 15: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

1252 T p tin AndroidManifestxml ậ Đacircy đ c xem lagrave t p tin quan tr ng nh tượ ậ ọ ấ

c a d aacuten Android T p tin nagravey ch a t t c nh ng thocircng tin c a d aacuten Tr c khiủ ự ậ ứ ấ ả ữ ủ ự ướ

ng d ng đ c th c thi h th ng s đ c nh ng thocircng tin nagravey T p tinứ ụ ượ ự ệ ố ẽ ọ ữ ậ

AndroidManifestxml ch a nh ng thocircng tin c b n sauứ ữ ơ ả

Tecircn Package

Caacutec thagravenh ph n c a ng d ng hi n coacute Activity Services Contentầ ủ ứ ụ ệ

Providers ho c Broadcast Receiverặ

Quy n h n c a ng d ngề ạ ủ ứ ụ

M t t p tin ộ ậ AndroidManifest xml m uẫltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid package=androidcooktest androidversionCode=1 androidversionName=10gt

ltuses-sdk androidminSdkVersion=9 androidtargetSdkVersion=15 gt

ltapplication androidlabel=stringapp_name androidicon=drawableic_launcher androidtheme=styleAppThemegt

ltreceiver androidname=HelloAndroidWidgetProvider androidpermission=androidpermissionSET_WALLPAPERgt

ltintent-filter gt ltaction

androidname=androidappwidgetactionAPPWIDGET_UPDATE gt ltintent-filtergt ltmeta-data

androidname=androidappwidgetprovider

androidresource=xmlhelloandroidprovidergtltreceivergt

ltapplicationgtltmanifestgt

+ Application Resources

1252 Application Resources (tagravei nguyecircn ng d ng)ứ ụ đ c s d ng đ thi tượ ử ụ ể ế

k giao di n cung c p higravenh nh acircm thanh cho ng d ng Tacirct c caacutec tagravei nguyecircnế ệ ấ ả ứ ụ ả

ng d ng đ c l u trong th m c resứ ụ ượ ư ư ụ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 16: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Khi m t tagravei nguyecircn đ c thecircm vagraveo Android SDK s phaacutet sinh m t s ID t ngộ ượ ẽ ộ ố ươ

ng trong t p tin Rjavaứ ậ Viacute d t p tin Rjava ng v i tagravei nguyecircn m u trecircnụ ậ ứ ớ ẫ

125 C u truacutec l u tr ấ ư ữ m t d aacuten Androidộ ự

Higravenh sau minh h a c u truacutecọ ấ l u tr m t d aacuten Android ư ữ ộ ự

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 17: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Coacute m t s th m cộ ố ư ụ vagrave t p tin quan tr ng c n quan tacircm sauậ ọ ầ

Th m c ư ụ RES l u tr caacutec t p tin tagravei nguyecircnư ữ ậ

Th m c ư ụ SRC l u tr toagraven b t p tin Java trong ng d ng Caacutec t p tinư ữ ộ ậ ứ ụ ậ

(class) đ c t ch c thagravenh caacutec goacutei (package) javaượ ổ ứ

Th m c ư ụ GEN ch a t p tin Rjava đ c dugraveng đ truy xu t caacutec tagravei nguyecircnứ ậ ượ ể ấ

khi vi t matildeế

T p tin ậ AndroidManifestxml ch a thocircng tin v ng d ngứ ề ứ ụ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 18: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Ch ng 2 T ng h p m t s l p quan tr ng trecircn n n t ngươ ổ ợ ộ ố ớ ọ ề ả

Android

Caacutec l p nagravey đ c gi i thi u ớ ượ ớ ệ developerandroidcomreferencepackageshtml Trong ch ng trigravenh nagravey taacutec gi t ng h p m t s l p ph ng th c c b n đ cươ ả ổ ợ ộ ố ớ ươ ứ ơ ả ượ dugraveng trong giai đo n nghiecircn c u nagraveyạ ứ

21 L p androidappActivityớ

Ki uể Tecircn ph ng th cươ ứ Ch c năngứvoid addContentView() Thecircm m t view vagraveo Activityộvoid closeContextMenu() Đoacuteng menu ng c nh hi n hagravenh (n uữ ả ệ ế

đang m )ởvoid closeOptionsMenu() Đoacuteng menu optionsview findViewById() Tigravem m t view theo thu c tiacutenh ID c aộ ộ ủ

file XMLvoid finish() G i khi Activity đoacuteng l iọ ạvoid finishActivity() Bu c m t activity khaacutec đoacuteng l iộ ộ ạIntent getIntent() Tr l i Intent kh i đ ng Activityở ạ ở ộMenuInflater getMenuInflater() T o m t đ i t ng MenuInflaterạ ộ ố ượvoid onCreateContextMenu() G i khi t o menu contextọ ạboolean onCreateOptionsMenu() Kh i t o n i dung c a menu optionsở ạ ộ ủvoid setContentView() Đ a m t view đ Activity hi n th ư ộ ể ể ị

void onCreate() Đ c g i khi Activity đ c t o l nượ ọ ượ ạ ầ đ uầ

void onDestroy Đ c g i tr c khi Activity đ c h yượ ọ ướ ượ ủ hoagraven toagraven

void onPause() Đ c g i khi Activity b che khu tượ ọ ị ấvoid onRestart() Hi n th vagrave focus l i Activity tr ngể ị ạ ở ạ

thaacutei stoppedvoid onResume() Đ cg i khi Activity b t đ u t ngượ ọ ắ ầ ươ

taacutec v i userớvoid onStart() Đ c g i khi Activity đang hi n thượ ọ ể ịvoid onStop() Đ c g i khi Activity b che khu tượ ọ ị ấ

hoagraven toagravenvoid

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 19: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

21 L p androidappAlertDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th trigravenh bagravey h p tho iộ ớ ủ ớ ể ộ ạ coacute m t hai ho c ba buttonsộ ặ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứButton getButton(int whichButton)

L y ra m t nuacutet trong caacutec nuacutet đ c s d ng trong dialogấ ộ ượ ử ụListview getListView()

L y ra m t listview đ c s d ng trong dialogấ ộ ượ ử ụboolean onKeyDown(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấboolean onKeyUp(int keyCode KeyEvent event)

Đ c g i khi m t phiacutem đ c th ượ ọ ộ ượ ảvoid setButton(int whichButton CharSequence text

DialogInterfaceOnClickListener listener)Thi t đ t s ki n l ng nghe khi nuacutet d ng c a dialog đ c nh nế ặ ự ệ ắ ươ ủ ượ ấ

void setButton(int whichButton CharSequence text Message msg)Thi t đ t thocircng baacuteo khi nuacutet đ c nh nế ặ ượ ấ

void setIcon(int resId)Thi t đ t Icon (0 khi khocircng mu n coacute Icon)ế ặ ố

void setIconAttribute(int attrId)Thi t đ t thu c tiacutenh b sung cho iconế ặ ộ ổ

void setTitle(CharSequence title)Thi t đ t tiecircu đ cho h p tho iế ặ ề ộ ạ

void setView(View view)Thi t đ t m t view trigravenh bagravey trong dialogế ặ ộ

22 L p androidappDatePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a DatePickerộ ớ ủ ớ ể ứ (b ch n ngagravey)ộ ọ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứDatePicker getDatePicker()

Gets the DatePicker contained in this dialogvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onDateChanged(DatePicker view int year int month int day)

Đ c g i khi ngagravey thay đ iượ ọ ổvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 20: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Bundle onSaveInstanceState()L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủ

void updateDate(int year int monthOfYear int dayOfMonth)Thi t đ t ngagravey hi n hagravenhế ặ ệ

23 L p androidappDialogớ

Ch c năngứ Đacircy lagrave l p Base c a caacutec l p con Dialogớ ủ ớ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid addContentView(View view ViewGroupLayoutParams params)

Thecircm m t view vagraveo magraven higravenhộvoid cancel()

H y Dialogủvoid closeOptionsMenu()

Đoacuteng menu Optionsvoid dismiss()

Lo i b h p tho i ra kh i magraven higravenhạ ỏ ộ ạ ỏboolean dispatchGenericMotionEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n chuy n đ ng chungọ ể ử ự ệ ể ộboolean dispatchKeyEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutemọ ể ử ự ệboolean dispatchKeyShortcutEvent(KeyEvent event)

G i đ x lyacute caacutec s ki n phiacutem noacutengọ ể ử ự ệboolean dispatchTouchEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n Touchọ ể ử ự ệboolean dispatchTrackballEvent(MotionEvent ev)

G i đ x lyacute caacutec s ki n trackball ọ ể ử ự ệView findViewById(int id)

Tigravem m t view theo thu c tiacutenh IDộ ộActionBar getActionBar()

L y ActionBar g n vagraveo h p tho i n u coacuteấ ắ ộ ạ ếContext getContext()

L y context magrave h p tho i đang ch y trong đoacuteấ ộ ạ ạView getCurrentFocus()

G i ph ng th c getCurrentFocus() trecircn c a s ọ ươ ứ ử ổActivity getOwnerActivity()

Tr v Activity coacute h p tho i nagraveyả ề ộ ạwindow getWindow()

L y c a s hi n hagravenh cho Activityấ ử ổ ệvoid hide()

Lagravem n dialog nh ng khocircng lo i b noacuteẩ ư ạ ỏvoid onActionModeFinished(ActionMode mode)

Đ c g i khi ki u action đatilde hoagraven thagravenhượ ọ ểvoid onActionModeStarted(ActionMode mode)

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 21: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Đ c g i khi ki u action đatilde b t đ uượ ọ ể ắ ầ

void onAttachedToWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

void onBackPressed()Đ c g i khi dialog phaacutet hi n phiacutem back đ c nh nượ ọ ệ ượ ấ

void onContentChanged()Đ c g i b t c luacutec nagraveo n i dung view c a magraven higravenh thay đ iượ ọ ấ ứ ộ ủ ổ

void onCreateContextMenu(ContextMenu menu View v ContextMenuContextMenuInfo menuInfo)Đ c g i khi t o menu context c a viewượ ọ ạ ủ

boolean onCreateOptionsMenu(Menu menu)Đ c g i khi t o menu Optionsượ ọ ạ

boolean onCreatePanelMenu(int featureId Menu menu)Kh i t o n i dung c a menu cho panelở ạ ộ ủ

View onCreatePanelView(int featureId)Kh i t o view đ trigravenh bagravey trong panelở ạ ể

void onDetachedFromWindow()Đ c g i khi m t c a s đ c g n vagraveo trigravenh qu n lyacute c a s ượ ọ ộ ử ổ ượ ắ ả ử ổ

boolean onKeyDown(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh nượ ọ ộ ượ ấ

boolean onKeyLongPress(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c nh n vagrave giượ ọ ộ ượ ấ ữ

boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)Đ c g i khi phiacutem đ c nh n nhi u l nượ ọ ượ ấ ề ầ

boolean onKeyShortcut(int keyCode KeyEvent event)Đ c g i khi phiacutem noacuteng đ c nh nượ ọ ượ ấ

boolean onKeyUp(int keyCode KeyEvent event)Đ c g i khi m t phiacutem đ c thượ ọ ộ ượ ả

boolean onMenuItemSelected(int featureId MenuItem item)Đ c g i khi m t m c trecircn menu đ c ch nượ ọ ộ ụ ượ ọ

boolean onMenuOpened(int featureId Menu menu)Đ c g i khi menu trecircn panel đ c m b i ng i dugravengượ ọ ượ ở ở ườ

void onPanelClosed(int featureId Menu menu)Đ c g i khi panel đoacutengượ ọ

boolean onPrepareOptionsMenu(Menu menu)Đ c g i khi menu Options coacute s a đ iượ ọ ử ổ

boolean onPreparePanel(int featureId View view Menu menu)Đ c g i khi panelcoacute s a đ iượ ọ ử ổ

void onRestoreInstanceState(Bundle savedInstanceState)Ph c h i tr ng thaacutei c a dialog t bundleụ ồ ạ ủ ừ

Bundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 22: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

L u tr ng thaacutei c a dialog vagraveo bundleư ạ ủboolean onSearchRequested()

Đ c g i khi b t đ u th c hi n yecircu c u tigravem ki mượ ọ ắ ầ ự ệ ầ ế

boolean onTouchEvent(MotionEvent event)Đ c g i khi coacute s ki n touchượ ọ ự ệ

boolean onTrackballEvent(MotionEvent event)Đ c g i khi coacute s ki n Trackballượ ọ ự ệ

void onWindowAttributesChanged(WindowManagerLayoutParams params)Đ c g i khi coacute s thay đ i thu c tiacutenh c a c a s hi n hagravenhượ ọ ự ổ ộ ủ ử ổ ệ

void onWindowFocusChanged(boolean hasFocus)Đ c g i khi focus c a c a s thay đ iượ ọ ủ ử ổ ổ

ActionMode onWindowStartingActionMode(ActionModeCallback callback)Đ c g i khi ki u action c a c a s b t đ uượ ọ ể ủ ử ổ ắ ầ

void setCancelMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog đoacutengế ặ

void setCancelable(boolean flag)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setContentView(View view)Đ t n i dung magraven higravenh vagraveo viewặ ộ

void setDismissMessage(Message msg)Thi t đ t thocircng baacuteo khi dialog b h yế ặ ị ủ

void setOnCancelListener(DialogInterfaceOnCancelListener listener)Thi t đ t s ki n l ng nghe khi dialog b h yế ặ ự ệ ắ ị ủ

void setOnShowListener(DialogInterfaceOnShowListener listener)Thi t đ t s ki n l ng nghe khi dialog hi n th ế ặ ự ệ ắ ể ịSets a listener to be invoked when the dialog is shown

void setOwnerActivity(Activity activity)Gaacuten tecircn Activity coacute dialog nagravey

void setTitle(int titleId)Gaacuten tiecircu đ cho dialogề

void show()Kh i đ ng dialog vagrave trigravenh bagravey noacute trecircn magraven higravenhở ộ

24 L p androidappớ ProgressDialog

Ch c năngứ Đacircy lagrave m t l p con Dialog trigravenh bagravey h p tho i ti n trigravenhộ ớ ộ ạ ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onStart()

Đ c g i khi dialog kh i t oượ ọ ở ạ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 23: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

void setProgressNumberFormat(String format)Thay đ i d ng s c a h p ti n trigravenhổ ạ ố ủ ộ ế

void setProgressPercentFormat(NumberFormat format)Thay đ i d ng s ph n trăm c a h p ti n trigravenhổ ạ ố ầ ủ ộ ế

25 L p androidappServiceớ

Ch c năngứ Đacircy lagrave l p x lyacute thagravenh ph n services c a ng d ngớ ử ầ ủ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứApplication getApplicatio n ()

Tr v ng d ng coacute service nagraveyả ề ứ ụIBinder onBind(Intent intent)

Tr v kecircnh truy n thocircng đ n serviceả ề ề ếvoid onConfigurationChanged(Configuration newConfig)

Đ c g i b i h th ng khi c u higravenh thi t b thay đ iượ ọ ở ệ ố ấ ế ị ổvoid onCreate()

Đ c g i b i h th ng khi service đ c t o l n đ uượ ọ ở ệ ố ượ ạ ầ ầvoid onDestroy()

Đ c g i b i h th ng khi service b h y bượ ọ ở ệ ố ị ủ ỏvoid onLowMemory()

Đ c g i b i h th ng khi b nh suy gi mượ ọ ở ệ ố ộ ớ ảvoid onRebind(Intent intent)

Đ c g i khi coacute m t ng i dugraveng m i k t n i v i serviceượ ọ ộ ườ ớ ế ố ớvoid onStartCommand(Intent intent int flags int startId)

Đ c g i b i h th ng khi coacute m t ng i dugraveng b t đ u s d ngượ ọ ở ệ ố ộ ườ ắ ầ ử ụ service m t caacutech t ng minhộ ườ

void onTaskRemoved(Intent rootIntent)Đ c g i n u service đang ch y vagrave ng i dugraveng đatilde lo i taacutec v coacuteượ ọ ế ạ ườ ạ ụ t ng d ng c a serviceừ ứ ụ ủ

void onTrimMemory(int level)Đ c g i khi h đi u hagravenh phaacutet hi n ra th i đi m c n đ c t b tượ ọ ệ ề ệ ờ ể ầ ể ắ ớ b nh khocircng c n thi t ra kh i ti n trigravenhộ ớ ầ ế ỏ ế

boolean onUnbind(Intent intent)Đ c g i khi t t c ng i dugraveng m i khocircng k t n i v i serviceượ ọ ấ ả ườ ớ ế ố ớ

void startForeground(int id Notification notification)B t đ u ch y ch đ n nắ ầ ạ ế ộ ề

void stopF oreground (boolean removeNotification)K t thuacutec ch y ch đ n nế ạ ế ộ ề

void stopSelf()T d ng serviceự ừ

26 L p androidappTimePickerDialogớ

Ch c năngứ Đacircy lagrave m t l p con c a l p Dialog coacute th ch a TimePickerộ ớ ủ ớ ể ứ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 24: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onClick(DialogInterface dialog int which)

Đ c g i khi kiacutech m t nuacutet trong dialogượ ọ ộvoid onRestoreInstanceState(Bundle savedInstanceState)

Ph c h i tr ng thaacutei c a dialog t Bundleụ ồ ạ ủ ừBundle onSaveInstanceState()

L u tr ng thaacutei c a dialog vagraveo Bundleư ạ ủvoid onTimeChanged(TimePicker view int hourOfDay int minute)

Đ c g i khi gi thay đ iượ ọ ờ ổvoid updateTime(int hourOfDay int minutOfHour)

C p nh t giậ ậ ờ

27 L p androidappwidgetAppWidgetManagerớ

Ch c năngứ C p nh t tr ng thaacutei AppWidget cung c p thocircng tin vậ ậ ạ ấ ề AppWidget provider đatilde cagravei đ t vagrave caacutec tr ng thaacutei liecircn quan khaacutecặ ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứboolean bindAppWidgetIdIfAllowed(int appWidgetId ComponentName

provider)Thi t đ t component cho m t appWidgetIdế ặ ộ

int[] getAppWidgetIds(ComponentName provider)Cung c p danh saacutech appWidgetIds ragraveng bu c v i AppWidgetấ ộ ớ provider

AppWidget_ProviderInfo

getAppWidgetInfo(int appWidgetId)Cung c p thocircng tin v AppWidgetấ ề

Bundle getAppWidgetOptions(int appWidgetId)Cung c p extras k t h p v i th c th Widgetấ ế ợ ớ ụ ể

AppWidget_Manager

getInstance(Context context)Cung c p th c th AppWidgetManager đ dugraveng cho đ i t ngấ ự ể ể ố ượ Context

void notifyAppWidgetViewDataChanged(int[] appWidgetIds int viewId)Thocircng baacuteo m t t p caacutec view trong t t c caacutec th c th AppWidgetộ ậ ấ ả ự ể xaacutec đ nh đ lagravem m t hi u l c d li u hi n hagravenh c a chuacutengị ể ấ ệ ự ữ ệ ệ ủ

void partiallyUpdateAppWidget(int appWidgetId RemoteViews views)Th c hi n c p nh t trecircn m t widget đ c ch đ nh b iự ệ ậ ậ ộ ượ ỉ ị ở appWidgetId

void updateAppWidget(int[] appWidgetIds RemoteViews views)Set the RemoteViews to use for the specified appWidgetIds

void updateAppWidget(ComponentName provider RemoteViews views)

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 25: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Thi t đ t RemoteViews dugraveng cho t t c caacutec th c th AppWidgetế ặ ấ ả ụ ểvoid updateAppWidgetOptions(int appWidgetId Bundle options)

C p nh t extras đ i v i th c th widget đatilde choậ ậ ố ớ ụ ể

28 L p androidappwidgetAppWidgetProviderớ

Ch c năngứ Cung c p caacutech cagravei đ t m t AppWidget providerấ ặ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid onAppWidgetOptionsChanged(Context context

AppWidgetManager appWidgetManager int appWidgetId Bundle newOptions)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứACTION_APPWIDGET_OPTIONS_CHANGED khi widget nagravey thay đ i ổ kiacutech th cướ

void onDeleted(Context context int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DELETED khi coacute m t hay nhi u ộ ề widget b h yị ủ

void onDisabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_DISABLED khi widget cu i cugraveng b h yố ị ủ

void onEnabled(Context context)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_ENABLED khi coacute widget đ c kh i t oượ ở ạ

void onReceive(Context context Intent intent)Cagravei đ tặ onReceive(Context Intent) đ g iể ử caacutec l iờ g i đ nọ ế caacutec ph ngươ th cứ khaacutec nhau trecircn AppWidgetProvider

void onUpdate(Context context AppWidgetManager appWidgetManager int[] appWidgetIds)Đ c g i ượ ọ để đaacutep ng thocircng baacuteo ứ ACTION_APPWIDGET_UPDATE khi AppWidget provider nagravey đ c yecircu c u cung c p RemoteViews choượ ầ ấ t p caacutec AppWidgetsậ

29 L p androidcontentBroadcastReceiverớ

Ch c năng ứ L p Base cho matilde x lyacute intents đ c g i b i sendBroadcast()ớ ử ượ ở ở

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứvoid abortBroadcast()

Thi t l p c bi u th receiverế ậ ờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạvoid clearAbortBroadcast()

Xoacutea c bi u th receiverờ ể ị (intent) b qua thocircng baacuteo hi n t iỏ ệ ạboolean getAbortBroadcast()

Tr v tr ng thaacutei c a c ch thả ề ạ ủ ờ ỉ ịint getResultCode()

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 26: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Cung c p matilde k t qu hi n hagravenhấ ế ả ệString getResultData()

Cung c p d li u k t qu hi n hagravenhấ ữ ệ ế ả ệBundle getResultExtras(boolean makeMap)

Cung c p d li u extras k t qu hi n hagravenhấ ữ ệ ế ả ệboolean isOrderedBroadcast()

Tr v true n u receiver đang x lyacute m t thocircng baacuteo coacute th tả ề ế ử ộ ứ ựvoid onReceive(Context context Intent intent)

Đ c g i khi BroadcastReceiver đang nh n thocircng baacuteo Intentượ ọ ậvoid setResult(int code String data Bundle extras)

Thay đ i t t c d li u k t qu tr v t thocircng baacuteoổ ấ ả ữ ệ ế ả ả ề ừvoid setResultCode(int code)

Thay đ i matilde k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủvoid setResultData(String data)

Thay đ i d li u k t qu hi n hagravenh c a thocircng baacuteoổ ữ ệ ế ả ệ ủvoid setResultExtras(Bundle extras)

Thay đ i extras k t qu hi n hagravenh c a thocircng baacuteoổ ế ả ệ ủ

210 L p androidcontentContextớ

Ch c năng ứ X lyacuteử giao di n thocircng tin toagraven c c v mocirci tr ng ng d ngệ ụ ề ườ ứ ụ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

boolean bindService(Intent service ServiceConnection conn int flags)K t n i v i ng d ng service t o ra noacute n u c nế ố ớ ứ ụ ạ ế ầ

int checkCallingOrSelfPermission(String permission)Xaacutec đ nh đ i t ng gaacuten quy n đ c bi t (IPC hay ng i dugraveng)ị ố ượ ề ặ ệ ườ

int checkCallingOrSelfUriPermission(Uri uri int modeFlags)Xaacutec đ nh đ i t ng gaacuten quy n truy c p URIị ố ượ ề ậ

int checkCallingPermission(String permission)Xaacutec đinh coacute ph i IPC đ c gaacuten quy n đ c bi tả ượ ề ặ ệ

int checkCallingUriPermission(Uri uri int modeFlags)Xaacutec đinh coacute ph i ti n trigravenh đang g i vagrave User đ c gaacuten quy n truy c pả ế ọ ượ ề ậ URI

int checkUriPermission(Uri uri String readPermission String writePermission int pid int uid int modeFlags)Ki m tra c hai quyể ả n URI vagrave quy n normalề ề

Context createConfigurationContext(Configuration overrideConfiguration)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i c u higravenh đatilde choỉ ợ ớ ấ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 27: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Context createDisplayContext(Display display)Tr v đ i t ng Context m i nh ng tagravei nguyecircn c a noacute đ c đi uả ề ố ượ ớ ư ủ ượ ề ch nh phugrave h p v i kiacutech th c magrave higravenh đatilde choỉ ợ ớ ướ

Context createPackageContext(String packageName int flags)Tr v đ i t ng Context m i v i tecircn ng d ng đatilde choả ề ố ượ ớ ớ ứ ụ

String[] databaseList()Tr v m ng tecircn caacutec CSDL k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

boolean deleteDatabase(String name)H y m t SQLiteDatabase k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

boolean deleteFile(String name)H y m t File k t h p v i goacutei ng d ng c a Contextủ ộ ế ợ ớ ứ ụ ủ

String[] fileList()Tr v m ng tecircn caacutec files k t h p v i goacutei ng d ng c a Contextả ề ả ế ợ ớ ứ ụ ủ

Context getApplicationContext()Tr v n i dung đ i ng d ng đ n toagraven c c c a ti n trigravenh hi nả ề ộ ố ứ ụ ơ ụ ủ ế ệ hagravenh

ApplicationInfo

getApplicationInfo()Tr v thocircng tin ng d ng đ i v i goacutei contextả ề ứ ụ ố ớ

File getCacheDir()Tr v đ ng d n tuy t đ i đ n th m c ng d ngả ề ườ ẫ ệ ố ế ư ụ ứ ụ

File getDatabasePath(String name)Tr v đ ng d n tuy t đ i đ n CSDL ng d ngả ề ườ ẫ ệ ố ế ứ ụ

File getDir(String name int mode)L y ra t o m i th m c magrave ng d ng coacute th đ t vagraveo caacutec file d li uấ ạ ớ ư ụ ứ ụ ể ặ ữ ệ riecircng

File getFileStreamPath(String name)Tr v đ ng d n tuy t đ i c a trecircn filesystem ả ề ườ ẫ ệ ố ủ

Resources getResources()Tr v th c th Resources c a goacutei ng d ngả ề ự ể ủ ứ ụ

void grantUriPermission(String toPackage Uri uri int modeFlags)Gaacuten quy n truy c p Uri cho goacutei ng d ng khaacutecề ậ ứ ụ

boolean isRestricted()Cho bi t Context b h n ch khocircngế ị ạ ế

FileInputStream

openFileInput(String name)M file k t h p v i goacutei ng d ng Context đ đ cở ế ợ ớ ứ ụ ể ọ

FileOutputStream

openFileOutput(String name int mode)M file k t h p v i goacutei ng d ng Context đ vi tở ế ợ ớ ứ ụ ể ế

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 28: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

SQLiteDatabase

openOrCreateDatabase(String name int mode SQLiteDatabaseCursorFactory factory)M SQLiteDatabase k t h p v i goacutei ng d ng Contextở ế ợ ớ ứ ụ

void revokeUriPermission(Uri uri int modeFlags)Lo i b t t c caacutec quy n truy c p ạ ỏ ấ ả ề ậ content provider Uri

void sendBroadcast(Intent intent)Truy n intent đ n t t c caacutec BroadcastReceivers đ c quan tacircmề ế ấ ả ượ

void setTheme(int resid)Thi t đ t theme c s cho contextế ặ ơ ở

void startActivities(Intent[] intents Bundle options)Kh i đ ng caacutec Activites m iở ộ ớ

void unbindService(ServiceConnection conn)T t k t n i v i m t ng d ng serviceắ ế ố ớ ọ ứ ụ

211 L p androidcontentIntentớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

Intent addCategory(String category)Thecircm m t category cho intentộ

Intent addFlags(int flags)Thecircm m t flags cho intentộ

Object clone()T o vagrave tr v m t b n sao c a đ i t ng (this)ạ ả ề ộ ả ủ ố ượ

Intent cloneFilter()T o vagrave tr v m t b n sao c a đ i t ng (this) coacute l c ạ ả ề ộ ả ủ ố ượ ọ

int fillIn(Intent other int flags)Copy n i dung c a ộ ủ other vagraveo trong intent nagravey nh ng ch nh ng tr ngư ỉ ữ ườ khocircng đ c đ nh nghĩa b i intentượ ị ở

boolean filterEquals(Intent other)Xaacutec đ nh xem hai intents coacute gi ng nhau v m c điacutech khocircngị ố ề ụ

int filterHashCode()Phaacutet sinh matilde hash phugravec h p v i ng nghĩa c a filterEquals()ợ ớ ữ ủ

String getAction()L y ra hagravenh đ ng t ng quaacutet đ c th c hi n nh lagrave ấ ộ ổ ượ ự ệ ư ACTION_VIEW

boolean[] getBooleanArrayExtra(String name)L y ra d li u m r ng t intentấ ữ ệ ở ộ ừ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 29: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

ClipData getClipData()Tr v ả ề ClipData k t h p v i ế ợ ớ Intent

ComponentName

getComponent()L y ra thagravenh ph n c th k t h p v i intentấ ầ ụ ể ế ợ ớ

Uri getData()L y ra d li u magrave intent đang x lyacuteấ ữ ệ ử

String getDataString()Gi ng nh ố ư getData() nh ng tr v URI nh lagrave chu i matildeư ả ề ư ỗ

Bundle getExtras()L y ra d li u extras m r ng t intentấ ữ ệ ở ộ ừ

int getFlags()L y ra c đ c bi t b t kỳ k t h p v i intentấ ờ ặ ệ ấ ế ợ ớ

String getScheme()Tr v ph n s đ d li u c a intentả ề ầ ơ ồ ữ ệ ủ

Intent getSelector()Tr v selector xaacutec đ nh k t h p v i Intentả ề ị ế ợ ớ

Rect getSourceBounds()L y v ragraveng bu c ng i g i intent theo t a đ magraven higravenhấ ề ộ ườ ở ọ ộ

String getType()L y ra ki u MIME t ng minh bao g m trong intentấ ể ườ ồ

boolean hasCategory(String category)Ki m tra xem category coacute t n t i trong intentể ồ ạ

boolean hasExtra(String name)Tr v true n u giaacute tr extra value đ c k t h p v i nameả ề ế ị ượ ế ợ ớ

Intent makeMainActivity(ComponentName mainActivity)T o ra m t intent đ trigravenh bagravey activity chiacutenhạ ộ ể

Intent makeMainSelectorActivity(String selectorAction String selectorCategory)T o ra m t Intent cho activity chiacutenhạ ộ

String normalizeMimeType(String type)Chu n hoacutea ki u d li u MIMEẩ ể ữ ệ

Intent parseIntent(Resources resources XmlPullParser parser AttributeSet attrs)Đ i ph n t intent element (vagrave caacutec children) t XML vagrave t o ra đ iổ ầ ử ừ ạ ố t ng Intentượ

Intent parseUri(String uri int flags)T o m t intent t ạ ộ ừ URI

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 30: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Intent putExtra(String name double[] value)Thecircm d li u m r ng cho intentữ ệ ở ộ

Intent putExtras(Intent src)Copy t t c extras trong src vagraveo intentấ ả

Intent putExtras(Bundle extras)Thecircm t p d li u m r ng cho intentậ ữ ệ ở ộ

void removeCategory(String category)Lo i category ra kh i intentạ ỏ

void removeExtra(String name)Lo i d li u m r ng ra kh i intentạ ữ ệ ở ộ ỏ

Intent replaceExtras(Bundle extras)Thay th hoagraven toagraven extras trong Intent b ng extras trong ể ằ Bundle

ComponentName

resolveActivity(PackageManager pm)Tr v thagravenh ph n Activity component đ c s d ng b i intentả ề ầ ượ ử ụ ở

String resolveType(ContentResolver resolver)Tr v ki u d li u MIME c a intentả ề ể ữ ệ ủ

Intent setAction(String action)Thi t đ t action chung đ c th c hi nế ặ ượ ự ệ

void setClipData(ClipData clip)Thi t đ t ế ặ ClipData k t h p v i ế ợ ớ Intent

Intent setComponent(ComponentName component)Thi t đ t ế ặ Component k t h p v i ế ợ ớ Intent

Intent setData(Uri data)Thi t đ t ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndNormalize(Uri data)Chu n hoacutea vagrave thi t đ t ẩ ế ặ dữ li uệ k t h p v i ế ợ ớ Intent

Intent setDataAndType(Uri data String type)Thi t đ t ế ặ dữ li uệ cho Intent cugraveng v i ki u d li u MIMEớ ể ữ ệ

Intent setDataAndTypeAndNormalize(Uri data String type)Chu n hoacutea vagrave thi t đ t c d li u Uri vagrave ki u d li u MIMEẩ ế ặ ả ữ ệ ể ữ ệ

Intent setFlags(int flags)Thi t đ t c đi u khi n intentế ặ ờ ề ể

void setSelector(Intent selector)Thi t đ t selector cho Intentế ặ

Intent setType(String type)Thi t đ t ki u d li u MIMEế ặ ể ữ ệ

Intent setTypeAndNormalize(String type)

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 31: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Chu n hoacutea vagrave thi t đ t ki u d li u MIMEẩ ế ặ ể ữ ệ

String toUri(int flags)Đ i Intent thagravenh chu i bi u di n URI ổ ỗ ể ễ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 32: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

211 L p androidcontentresResourcesớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o vagrave x lyacute caacutec intentsấ ề ạ ử

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void flushLayoutCache()Lo i t t c caacutec resources trong b nh cache kh i đ i t ngạ ấ ả ộ ớ ỏ ố ượ Resources

boolean getBoolean(int id)Tr v m t giaacute tr boolean k t h p v i resource IDả ề ộ ị ế ợ ớ

int getColor(int id)Tr v m t s nguyecircn magraveu k t h p v i resource IDả ề ộ ố ế ợ ớ

ColorStateList

getColorStateList(int id)Tr v m t danh saacutech tr ng thaacutei magraveu k t h p resource IDả ề ộ ạ ế ợ

Configuration getConfiguration()Tr v c u higravenh hi n hagravenh đ i v i đ i t ng Resourcesả ề ấ ệ ố ớ ố ượ

float getDimension(int id)L y ra ấ dimensional đ i v i resource IDố ớ

DisplayMetrics

getDisplayMetrics()Tr v kiacutech th c magraven higravenh hi n hagravenhả ề ướ ệ

Drawable getDrawable(int id)Tr v m t đ i t ng drawable k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

float getFraction(int id int base int pbase)L y ra đ n v fractional đ i v i resource IDấ ơ ị ố ớ

int getIdentifier(String name String defType String defPackage)L y ra identifier ng v i name c a resourceấ ứ ớ ủ

int getInt(int id)Tr v m t s nguyecircn k t h p v i resource IDả ề ộ ố ế ợ ớ

Movie getMovie(int id)Tr v m t đ i t ng Movie k t h p v i resource IDả ề ộ ố ượ ế ợ ớ

String getResourceEntryName(int resid)Tr v tecircn ng v i identifierả ề ứ ớ c a ủ resource

void getValue(String name TypedValue outValue boolean resolveRefs)Tr v d liecircu thocirc k t h p v i resource IDả ề ữ ế ợ ớ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 33: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

void getValueForDensity(int id int density TypedValue outValue boolean resolveRefs)Tr v giaacute tr thocirc k t h p v i resource coacute density k t h pả ề ị ế ợ ớ ế ợ

ResourcesTheme

newTheme()Phaacutet sinh m t đ i tu ng Theme ng v i t p Resourcesộ ố ợ ứ ớ ậ

TypedArray

obtainAttributes(AttributeSet set int[] attrs)l y ra m t t p caacutec giaacute tr thu c tiacutenh c b n t AttributeSetấ ộ ậ ị ộ ơ ả ừ

InputStream

openRawResource(int id TypedValue value)M data stream đ đ c raw resourceở ể ọ

void updateConfiguration(Configuration config DisplayMetrics metrics)Ch a c u higravenh đatilde c p nh t m i nh tứ ấ ậ ậ ớ ấ

212 L p androidgraphicsColorớ

Ch c năng ứ Đ nh nghĩaị caacutec ph ng th c đ t o vagrave đ i caacutec s nguyecircnươ ứ ể ạ ổ ố color

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int HSVToColor(float[] hsv)Đ i caacutec thagravenh ph n HSV thagravenh magraveu ARGBổ ầ

void RGBToHSV(int red int green int blue float[] hsv)Đ i caacutec thagravenh ph n RGB thagravenh HSVổ ầ

int alpha(int color)Tr v thagravenh ph n alpha c a s nguyecircn magraveuả ề ầ ủ ố

int argb(int alpha int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n alpha red green blue ả ề ố ừ ầ

int blue(int color)Tr v thagravenh ph n blue c a s nguyecircn magraveuả ề ầ ủ ố

void colorToHSV(int color float[] hsv)Đ i magraveu ARGB thagravenh HSVổ

int blue(int color)Tr v thagravenh ph n green c a s nguyecircn magraveuả ề ầ ủ ố

int blue(int color)Tr v thagravenh ph n red c a s nguyecircn magraveuả ề ầ ủ ố

int rgb(int red int green int blue)Tr v s nguyecircn color t caacutec thagravenh ph n red green blueả ề ố ừ ầ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 34: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

213 L p androidmediaMediaPlayerớ

Ch c năng ứ L p MediaPlayer coacute th đ c s d ng đ đi u khi n vi cớ ể ượ ử ụ ể ề ể ệ phaacutet l i caacutec t p tin audio video vagrave streamạ ậ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void addTimedTextSource(Context context Uri uri String mimeType)Thecircm file ngu n d ng text thay đ i theo th i gian becircn ngoagravei(Uri)ồ ạ ổ ờ

void attachAuxEffect(int effectId)G n hi u ng ph vagraveo trigravenh playerắ ệ ứ ụ

void deselectTrack(int index)B ch n trackỏ ọ

int getAudioSessionId()Tr v ID c a audio ả ề ủ session

int getCurrentPosition()Cho v tr playback hi n hagravenhị ị ệ

int getDuration()Cho duration c a fileủ

TrackInfo[] getTrackInfo()Cho m ng thocircng tin trackả

int getVideoHeight()Tr v đ cao c a videoả ề ộ ủ

int getVideoWidth()Tr v đ r ng c a videoả ề ộ ộ ủ

boolean isLooping()Ki m tra xem MediaPlayer coacute l p l i hay khocircngể ặ ạ

boolean isPlaying()Ki m tra xem MediaPlayer coacute đang phaacutet hay khocircngể

void pause()T m d ng playbackạ ừ

void prepare()Chu n b trigravenh player đ playbackẩ ị ể

void release()Gi i phoacuteng resources g n v i đ i t ng MediaPlayerả ắ ớ ố ượ

void reset()Reset MediaPlayer tr l i tr ng thaacutei ch a kh i t oở ạ ạ ư ở ạ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 35: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

void seekTo(int msec)Tigravem v triacute time xaacutec đ nhị ị

void selectTrack(int index)Ch n trackọ

void setAudioSessionId(int sessionId)Thi t đ t ID cho audio sessionế ặ

void setAudioStreamType(int streamtype)Thi t đ t ki u audio stream cho MediaPlayerế ặ ể

void setAuxEffectSendLevel(float level)Thi t đ t level g i player cho hi u ng ph thecircm vagraveoế ặ ở ệ ứ ụ

void setDataSource(String path)Thi t đ t ngu n d li u (file-path or httprtsp URL)ế ặ ồ ữ ệ

void setDataSource(Context context Uri uri)Thi t đ t ngu n d li u nh content Uriế ặ ồ ữ ệ ư

void setDisplay(SurfaceHolder sh)Thi t đ t ế ặ SurfaceHolder đ trigravenh bagravey ph n ể ầ video c a mediaủ

void setLooping(boolean looping)Thi t đ t trigravenh player l p l i hay khocircngế ặ ặ ạ

void setNextMediaPlayer(MediaPlayer next)Thi t đ t MediaPlayer kh i đ ng khi MediaPlayer hoagraven thagravenh playbackế ặ ở ộ

void setSurface(Surface surface)Thi t đ t ế ặ Surface c a ph n videoủ ầ

void setVideoScalingMode(int mode)Thi t đ t ki u t l video (video scaling mode)ế ặ ể ỉ ệ

void setVolume(float leftVolume float rightVolume)Thi t đ t m c acircm thanh (volume) c a playerế ặ ứ ủ

void setWakeMode(Context context int mode)Thi t đ t qu n lyacute ngu n m c th p cho ế ặ ả ồ ứ ấ MediaPlayer

void start()B t đ u hay resumes playbackắ ầ

void stop()D ng playback sau khi playback đatilde b d ng hay t m d ngừ ị ừ ạ ừ

214 L p androidnetUriớ

Ch c năng ứ Dugraveng đ tham chi u Uriể ế

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 36: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

int compareTo(Uri other)So aacutenh bi u di n chu i c a Uri nagravey v i Uri khaacutecể ễ ỗ ủ ớ

String decode(String s)Gi i matilde ả -escaped octets trong chu i s d ng b matilde UTF-8ỗ ử ụ ộ

String encode(String s String allow)Matilde hoacutea caacutec kyacute t trong chu i d ng ự ỗ ạ -escaped octets s d ng b matildeử ụ ộ UTF-8

boolean equals(Object o)So saacutenh Uri v i đ i t ng khaacutec xem coacute b ng khocircngớ ố ượ ằ

Uri fromFile(File file)T o Uri t fileạ ừ

Uri fromParts(String scheme String ssp String fragment)T o Uri t caacutec thagravenh ph n đatilde cho trong tham sạ ừ ầ ố

String getAuthority()Cho ph n authority đatilde gi i matilde c a Uriầ ả ủ

boolean getBooleanQueryParameter(String key boolean defaultValue)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde cho vagrave di n gi i noacute nhỗ ấ ị ầ ớ ễ ả ư m t giaacute tr booleanộ ị

String getEncodedAuthority()Cho ph n authority đatilde matilde hoacutea c a Uriầ ủ

String getEncodedFragment()Cho ph n fragment đatilde matilde hoacutea c a Uriầ ủ

String getEncodedPath()Cho ph n path đatilde matilde hoacutea c a Uriầ ủ

String getEncodedQuery()Cho ph n query đatilde matilde hoacutea c a Uriầ ủ

String getEncodedUserInfo()Cho ph n thocircng tin user t authority đatilde matilde hoacutea ầ ừ

String getFragment()Cho ph n fragment đatilde gi i matilde c a Uriầ ả ủ

String getHost()Cho ph n thocircng tin host t authority đatilde matilde hoacuteaầ ừ

String getLastPathSegment()Cho ph n segment cu i cugraveng đatilde gi i matilde c a Uriầ ố ả ủ

String getPath()Cho ph n path đatilde gi i matildeầ ả

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 37: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

int getPort()Cho ph n port t authorityầ ừ

String getQuery()Cho ph n query đatilde gi i matilde c a Uriầ ả ủ

String getQueryParameter(String key)Tigravem chu i truy v n giaacute tr đ u tiecircn v i phiacutem đatilde choỗ ấ ị ầ ớ

String getScheme()Gets the scheme of this URI

String getUserInfo()Cho ph n thocircng tin user t authority đatilde gi i matildeầ ừ ả

boolean isAbsolute()Tr v ả ề true n u URI lagrave absoluteế

boolean

isHierarchical()Tr v true n u URI lagrave absolute ả ề ế hierarchical nh httpgooglecomư

boolean isOpaque()Tr v true n u URI lagrave ả ề ế opaque nh mailtonobodygooglecomư

boolean

isRelative()Tr v true n u URI lagrave ả ề ế relative

Uri normalizeScheme()Tr v URI t ng đ ng v i thagravenh ph n scheme vi t th ngả ề ươ ươ ớ ầ ế ườ

Uri parse(String uriString)T o Uri b ng caacutech chuy n chu i URI đatilde matilde hoacuteaạ ằ ể ỗ

String toString()Tr v chu i matilde hoacutea bi u di n URIả ề ỗ ể ễ

Uri withAppendedPath(Uri baseUri String pathSegment)T o m t Uri m i b ng caacutech b sung m t đo n Path đatilde matilde hoacutea vagraveo Uriạ ộ ớ ằ ổ ộ ạ

void writeToParcel(Parcel out Uri uri)Vi t Uri thagravenh m t Parcelế ộ

214 L p androidosHandlerớ

Ch c năng ứ L p x lyacute Handler cho pheacutep g i vaagrave x lyacute Message vagrave caacutec đ iớ ử ở ử ố t ng Runnable k t h p v i m t threadượ ế ợ ớ ộ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void dispatchMessage(Message msg)G i thocircng đi p h th ngở ệ ệ ố

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 38: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

String getMessageName(Message message)Tr v chu i bi u di n tecircn c a messageả ề ỗ ể ễ ủ

void handleMessage(Message msg)L p con ph i cagravei đ t đ nh n messageớ ả ặ ể ậ

boolean hasMessages(int what Object object)Ki m tra xem coacute message v i matilde what vagrave đ i t ng object trong hagravengể ớ ố ượ đ i khocircngiợ

Message obtainMessage()Tr v message m i t pool message toagraven c cả ề ớ ừ ụ

boolean post(Runnable r)T o ra đ i t ng Runnable r thecircm vagraveo hagraveng đ i messageạ ố ượ ợ

boolean postAtFrontOfQueue(Runnable r)G i message đ n m t đ i t ng coacute cagravei đ t Runnableở ế ộ ố ượ ặ

void removeCallbacks(Runnable r)Lo i b b t kỳ Runnable r coacute trong hagraveng đ i messageạ ỏ ấ ợ

void removeMessages(int what)Lo i b caacutec message v i matilde what trong hagraveng đ i khocircngạ ỏ ớ ợ

boolean sendEmptyMessage(int what)G i message ch ch a giaacute tr whatở ỉ ứ ị

boolean sendEmptyMessageAtTime(int what long uptimeMillis)G i ử m tộ message ch ch aỉ ứ giaacute trị what đ c giao ượ vagraveo m t th i đi mộ ờ ể cụ thể

boolean sendMessage(Message msg)G i message vagraveo cu i hagraveng đ i messageở ố ợ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

215 L p androidosMessageớ

Ch c năng ứ Đ nh nghĩa ị message ch a ph n mocirc t vagrave đ i t ng d li uứ ầ ả ố ượ ữ ệ b t kỳấ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void copyFrom(Message o)T o message cho b i oạ ở

Runnable getCallback()L y đ i t ng callback magrave s th c thi khi message đ c g iấ ố ượ ẽ ự ượ ở

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 39: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

Bundle getData()Nh n d li u k t h p v i s ki nậ ữ ệ ế ợ ớ ự ệ

Handler getTarget()L y ra ph n cagravei đ t ấ ầ ặ Handler nh n messageậ

long getWhen()Tr v th i đi m chuy n message đ n điacutech (tiacutenh b ng milliseconds)ả ề ờ ể ể ế ằ

Message obtain()Tr v th c th Message t global poolả ề ự ể ừ

void sendToTarget()G i Message đ n Handler đ c ch ra b i ph ng th cở ế ượ ỉ ở ươ ứ getTarget()

void setData(Bundle data)Đ t d li u d ng Bundleặ ữ ệ ạ

String toString()Tr v chu i ch a ph n mocirc t ng n c a đ i t ngả ề ỗ ứ ầ ả ắ ủ ố ượ

void writeToParcel(Parcel dest int flags)Flatten đ i t ng thagravenh Parcelố ượ

216 L p androidviewContextMenuớ

Ch c năng ứ Cung c p thocircng tin v caacutech t o Context Menuấ ề ạ

Caacutec ph ng th cươ ứ

Ki uể Tecircn ph ng th c vagrave ch c năngươ ứ ứ

void clearHeader()Xoacutea ph n ầ header c a context menu ủ

ContextMenu

setHeaderIcon(Drawable icon)Thi t đ t icon c a ph n header ế ặ ủ ầ

ContextMenu

setHeaderTitle(CharSequence title)Thi t đ t tiecircu đ c a ph n headerế ặ ề ủ ầ

ContextMenu

setHeaderView(View view)Thi t đ t header c a context menu choế ặ ủ View

21 L p ớ androidviewGravity

21 L p ớ androidviewMenu

21 L p ớ androidviewMenuInflater

21 L p ớ androidviewMenuItem

21 L p ớ androidviewView

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidviewViewGroupLayoutParamsớ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể

Page 40: Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng ...dulieu.tailieuhoctap.vn/books/cong-nghe-thong-tin/... · Ch ng 1: Các ki n th c c b n dùng cho l p trình ng d ng trênươ

21 L p androidwidgetArrayAdapterớ

21 L p androidwidgetButtonớ

21 L p androidwidgetDatePickerớ

21 L p androidwidgetEditTextớ

21 L p androidwidgetFrameLayoutớ

21 L p androidwidgetImageViewScaleTypeớ

21 L p androidwidgetImageViewớ

21 L p androidwidgetLinearLayoutớ

21 L p androidwidgetListViewớ

21 L p androidwidgetRelativeLayoutLayoutParamsớ

21 L p androidwidgetRelativeLayoutớ

21 L p androidwidgetTableLayoutớ

21 L p androidwidgetTableRowớ

21 L p androidwidgetTextViewớ

21 L p androidwidgetTimePickerớ

21 L p androidwidgetToastớ

21 L p javaioBufferedReaderớ

21 L p javaioInputStreamReaderớ

21 L p javanetURLớ

21 L p javautilCalendarớ

Ch ng 3 Xacircy d ng m t s ng d ng d a trecircn caacutec l p c a Androidươ ự ộ ố ứ ụ ự ớ ủ

K t lu n vagrave h ng phaacutet tri nế ậ ướ ể