BO GIAO DVC VA. RAO TAO THONG HAI HQC TWANG LONG KHOA LUAN TOT NG1110 TIM HIED VE PUSH NOTIFICATION XAY DING(ING DVNG NHAC LICH THI CHO SINN VIEN 'LUANG LONG TREN NEN TANG ANDROID Ths. U Minh Tuin Giao vien hirtrng din : Sinh thqc thiin : Pham Trung 1Cien — A14538 HO Chi Nghia — A14982 Cling Nghe: Thong Tin Chuyen nginh HA - 2014Lea NOI DAU Trong su phat trien manh me cita cong nghe thOng tin not chung va cong nghe di dOng n6i rieng, cac img dung di dOng dang d5n dung vai to5 quan tong trong vies img dung cong nghe thOng tin phts vu trong cuOc song con ngueri. C6ng nghe di dOng da dan chi'em linh vi tri trong cuOc song, chiem tru the ve so lug img dung ten cac thiet bt di dOng nhu dien thoai thong minh, may tinh bang, tivi thOng vainh...05 the not not trong c145 la nen tang Android manh me do co kha tang tuang thich yen nhieu thiet bat len i et viec nang cao chat luting tao ctia toting Dar hoc Thang Long la D cUng y vi'ec Ung dung hieu qui cac thanh tru cong nghe thong tin vao quan 19 dao tat) cung nhu truc tiep dao tao. Tren co sonheng kien thirc da duqc hoc trong cac min hoc tai truing ding nhu trong khuon kh6 cita mot de tai kh6a 1u5n tot nghiep, nhOm ditacc giah cap xa nhat y &gig qh mot phan mem chay ten nen tang di dOng Android yea rmyc p thi hoc k9 cho sinh vien Thang Long. Cling veti dO la tim hieu va tne tong pham vi kien thirc cira minh. Kh6a Wan nay duqc trinh bay thanh 5 chuang lem: — Chuang 1: GiOi thieu du an. Chuctng nay trinh bay 19 do nghien ciru va phucmg phap thuc hien khOa 1u5n; — Chuang 2: 1-le dieu hanh Android. Chuang nay Oen thieu can ban ve he dieu hanh Android, cac dac trong va kien trim ciia he dieu hanh; — Chuang 3: Giei thieu ve cong nghe Push Notification va Service trong Android. — Chuang 4: lThg dung nhic lich thi. Chuang nay trinh bay ve qui trinh phan tich thiet ke img dung; — Chuang 5: Cac k9 thuat xir 19 quan tong. Chuang nay trinh bay chi tiet han ve cac k9 that duqc sir dung trong xay dung img dung, qua trinh giri nh5n va xir 19 dit lieu cita cong nghe Push Notification. — Ket luan va hueng phat hien; — Cac tai lieu tham khao. Sau khi hoan thanh tai lieu nay, nh6m tic gia mong maul day cOng se la mot to lieu tham khao bit) ich cho cac sinh vien dang vi se tim hieu ve lap trinh Android ne chung, cilng nhu cong nghe Push Notification nOi rieng.Chung em xin chin thanh cam on thay giao Ths. Le Minh Titan da htromg din va giiip Ida chang em thiet ke - xay dirng va hoan thanh kluSa luAn nay. Cluing em cling xin gui 10i cam on den thAy giao Nguyen Dire Dan da ginp del cluing em ve mat ket not den di: lieu lich thi cua nha tnrang ding voi cac thay co b0 mon Tin hoc da tam huyet day 66 va dao tao chang em snot nhang nam Dai hoc. Ha Ni.e ngay 12 thing 04 nam 2014 Nh6m tic gia thirc hien: Pham Trung Kien HO Chi NghiaMIX LUC CHUONG 1. GIOT THIEU DV AN 1 1.1. Ten dE tai 1 1.2. IS do nghiOn ciru 1 1.3. Phtrcrng phap thtrc hiEn 2 CHUONG 2. HE DIEU HANH ANDROID VA PUSH NOTIFICATION 3 2.1. Glad thiEu he diet' hanh Android 3 2.2. Nhitng dac Hung caa hE diEu hanh Android 3 2.3. Cac tinh nang 118 try sari trong he diEu hanh Android 4 2.4. Kian tnic va cac thanh phan trong hg diEu hanh Android 5 2.5. Cac khai niEtn co ban trong lap trinh img dung Android 7 2.6. Cac thanh phan trong mot project zing dung Android 12 CHUONG 3. CONG NGHE PUSH NOTIFICATION VA SERVICE TRONG ANDROID 15 3.1. Giai thiEu ve cong nghE Push Notification 15 3.1.1. Tong quan 15 3.1.2. Thuat ngfr va khai niem lien quan 16 3.1.3. KiEn ink tong quan 17 3.1.4. Chu truth rang dal 18 3.2. Ling dung Push Notification trong img dung Android 19 3.2.1. Sc chi tang quan cac buoy trong qu6 trinh gzii nhan tin hieu 19 3.2.2. Thtrc hien thief lap Push Notification cho zing dung Android 20 Service tren Android 22 CHUONG 4. XAY DUNG trNG DUNG NHAC LICH THI CHO SINH VIEN THANG LONG 25 4.1. Tang quan yeu cau hg thong 25 4.1.1. Ma td 25 4.1.2. Hien trong tai truorg 25 4.1.3. Yeti cati nghiep vu 25 4.2. ling dung Android 264.2.1. M6 t 16 it 4.2.2. Sc do tong guar cac char nang chinh caa ang clung 16 4.2.3. Cac tac nhiin tham gia ,6 4.2.4. Coe char nang chinh caa img clung 26 4.2.5. Ccic thac the chinh 4.2.6. 130c to cac char non cua ang clung 4.3. ling dung may chit 4.3.1. A46 to 4.3.2. Sc do tang quart cac char ;ding cita may dui 4.3.3. Cac tcic nhan than, gia 4.3.4. Cac char 'ding chinh caa he theing 4.3.5. 100c to cac char ;Ong cita img dung 4.4. Phan tich thiet ke du liEu 4.4.1. MO to phcin tich di? lieu 4.4.2. Cau true bang 4.5. Ket qua xay Mpg img dung CHU'ONG 5. CAC Kt THU4T XU! LY QUAN TRQNG D5ng k9 thiet bi von GCM de nh5n RegistrationiD GM thong tin yEu cat' den may chic img dung (application server) Server nh5n thong tin va xii19 der liEu GM thong dip den GCM VT 19 thong dip dugc girl den tit GCM tren thiet bi Android Service trong Android Cai d5t hEn gia thong bio Kb' LthiiN VA HUONG PRAT TRIEN 1.Kat Juan 2.Huemg phat triezn TAI LIEU THAM KHAO 5.1. 5.2. 5.3. 5.4. 5.5. 5.6. 5.7. 5.8. CM d5t thin gian nhic lai thOng bac) 77 /7 57 57 58 58 58 58 66 66 67 67 68 68 69 70 72 73 74 77 78 79 79 79 80DANH MIJC CAC HINH MINH HOA Hinh 2.1. Kian trac cac thanh phan cua 116 diau hanh Android 5 Hinh 2.2. \Tong d'oi oh mat Activity 8 Hinh 2.3. ang &pi cila mat Service 9 Hinh 2.4. View 11 Hinh 2.5. Intent 11 Hinh 3.1. Man tit tong quan GCM 17 Hinh 3.2. So &Os tong quan cac btrac trong qua trinh giri nhan tin hiau 19 Hinh 3.3. Wong dari cua mot ServiceCHU'ONG 1. G1(11 THItU D11 AN 1.1. Ten de tai Tim hieu dich vu Push Notification, xay dung img dung nhic lich thi cho sinh vien Dai hoc ThAng Long. 1.2. LS/ do nghien cat Hien nay, viec &rig dung CNTT vao trong cong tac ciao tao ding nhu quart 19 cita tnramg Dai hoc Thang Long da tr& nen ph6 bien. Nhieu he thong, phAn mem duqc dua vao hoat dung nhAm lam tang hieu qua cong viec nhu He Hieing clang k9 hoc, He fixing dao tao true tuyen, cac phan mem quan 19 diem. tai chinh — ke Mac du da co nhimg btrerc phat hien trong suth qua trinh hoat clOng, di kern Yeti nhung thay dth ve cong tic giang day va quail 19 di° tao, cac he thring phan mem mdi luon duqc nang cap, thay the nhung phan mem he th6ng cu bang nhfmg phan mem he th6ng mai da dap irng tot nhu cau quart 19 va dio tar). Nhung van con dau do su thieu sot va han the cita nhung he thong phan mem hien tai. MOt minh chimg cho str han the tren d6 chinh la he thOng Dang k9 hoc true tuyen cua nha tnrang. vai vi du dua ra sau day co the chi ra sv han the nay: —Trudm khi k9 thi bit dal', nha truemg thong bao ve thai diem cong b6 lich thi chinh thirc, nhung den thai diem do lai xay ra mOt so truc frac ve k9 thuat khien may chit kheing the truy cop; —Khi gap str c6, may chit khOng the troy cap, sinh vien kitting theo clOi duqc lich thi elm minh, buOc ngay khi co duqc da lieu ye lich thi, sinh vien phai hr km trir lai bang cach ghi cher, lai lich thi Mac chop anh... gay bat tien cho sinh vien; —Khi co mOt str thay clth ve lich thi thi sinh vien }thong duqc canh bao hay co thong bao tir he th6ng, sinh vien phai to cop nhot lien toc lich thi cua minh; —Truck khi vao phi:mg thi sinh vien thong nha phong thi, tham chi ca thi ctia minh, sinh vien phai sir dung cac thiet bi lc& nth vth he thOng de co the biet duce thong tin, ngay hic nay, neu he tilting khong hoat doing thi sinh vier) se gap nhieu kh6 khan; —Do trong qua trinh On thi cang thAng, sinh vien qua mat lich thi. Tir nhfmg han the tren da thitc day chUng toi Oat trien mOt ow dung nhic lich thi, thing thai nghien dru phuong thirc tat nhAt de dap duqc str tien igi cho sinh vien trong qua trinh hoc tap tai tnremg Dai hoc Thang Long. Khi hoan thanh de tai nay, chUng tell se co ducic mOt Ung dung nit lich thi cho sinh vien chay duqc tren cac thiet bi di dOng cam tay nhu then thoai, may tinh bang...va darn bao duqc cac you cau co ban nhu: 1—Sinh vien se co dtrgc lich thi ngay khi lich thi chinh thirc dugc ban hanh; —DCr lieu ve lich thi khi c6 bat kY str thay 461 se duac thong bao ter' cho sinh vien, giap sinh vien chit clang trong viec on tap va thi cir; —Da lieu ve lich thi dtrgc luu tra ten thiet N va c6 the truy xuAt bAt kY hic nao, bAt lcY not dau. 1.3. Phircrng phi') thtyc hik'n De thtrc hien de tai nay, chUng tai se sir dung cling n2he Push Notification vi phat trien Ung dung tren nen tang Android. Cong nghe Push Notification se glop darn bac, dugc viec du lieu ve lich thi mai se ha& 'Aux cap nhot va thong bao taxi sinh vien. Nen tang Android cho phep irng dung c6 the chay dugc ten nhieu thiet bi di clang nhtr dien thoai thong minh hay may tinh bang. Can; yea su 'That trien ve nen tang di dang Android, nhieu thiet N di dOng khac trong tucrng lai chay he dieu hanh nay se c6 the sir dung dugc dng dung hire ich nay. He thong nay dua tit m6 hinh khach chn (client/server) bao gam 1 Web Service clang vai tr6 la Server dam bao ve dich vu truy xuat du lieu va mat Ung dung chay ten thiet bi di clang d6ng vai tre la Client. 2CHUONG 2. HE DIEU HANH ANDROID VA PUSH NOTIFICATION 2.1. Giiri thieu hg dieu hinh Android Android la mot he dieu hanh di dOng dua tren met phien ban sira den cua Linux. Dugc Oat trien vao nam 2005 aj mot du an ding ten "Android". Nhu mot ;lan chien !trot cua minh de Ian ski vac) link vtrc di &mg Google Android d5 mua ye toan 1)0 qua trinh Oat trien ciing nhu dOi phat trien no. Day la con at dhu bai cua Google de canh tranh thi phan he dieu hanh di clang vai Apple. Google Android muen ma va mien phi, vi vay hau het cac m5 Android dtrgc duce dtra ra dual clang ma ngu6n ma Apache License, dieu nay Wang duong vai viec bat cu ai mu6n sir dung Android al the lam nhu vay bang each tai ve ma nauen Android day Han nira cac nha cung cap (throng la nhfing nha phat trien phan cirng) c6 the them phan mo rOng va thy bien cho Android de phan biet san pham cua Ito yen san pham cua nhung ngulai khac. Dieu nay don gian lam cho mo hinh phat trien Android rat hap clan va do do khai day sy quan tam cua nhieu nha cung cap. Nhung nha san xuat coi Android nhu mot giai phap — ho se tiep tuc thiet ke phan cirng cua rieng minh va sir dung Android nhu mot he dieu hanh chinh. Liu diem chinh cua viec ap dung Android la no cung cap mot cach tiep can dicing nhat de phat trien img dung. Cac nha phat trien chi can phat trien cho Android va cac img dung cua ho có the chay tr'en nhieu thiet bi khac nhau, mien la cac thiet bi dugc h6 try bang cach sir dung Android. Trong the gieri dien thoai thong minh ling dung la mot phan quan trong nhat cua chu& thanh tong. Do de cac nha san xuAt thiet bi coi Android nhu la by ong tot nhat de thach third str tan ding dm Apple. 2.2. Nhiiing cl4c trtrng cua he dieu hinh Android —Application framework: cho phep sir dung lai va thay the cac thinh phAn trong lap trinh img dung; —Dalvik virtual machine: t6i tru hoa cho thiet bi di (Ring; —Intergrated browser: trinh duyet tich hop, dtra ten ca the WebKit ma- nguen ma; —SQLite: so so di' lieu trong mod truang di Ong; —Media support: hd. trey cac dinh dang audio, video va hinh anh thong dung; —GSM Telephony: mpg dien thoai di dOng (phu thuec vat) phan cirng); —Bluetooth, EDGE, 3G, vi WiFi: cac chuan ket not der lieu (phu thuOc vao phAn cling); —Camera, GPS, la bin, vi gia t6c We: (phu thuOc vao phAn cling); —Moi trtrirng phit trien phong phu: bao gem thiet bi me phOng, ding cu cho viec do tim 16i, bo nha va dinh hinh hieu nang va mot plugin cho Eclipse IDE. 32.3. Cic tinh nang 116 trq salt trong he diau hinh Android Cac tinh Wang dugc hg tit thy thugc vac, eau hinh phan ding va phi!) mem. —Storage: Sir dung SQLite, mgt co so da lieu quan he nhe cho viec km tit chi lieu; —Connectivity: H6 trq GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth (bao gam AD2P va AVRCP), Wifi, LTE va WiMAX; —Messaging: h6 trq ca SMS N/A MMS; —Web browser: Dua tren ma nguan mb Webkit. ding vari cong nghe JavaScript VA cga Chrome; —Media support: Bao gOm h6 trq cic phuung tien truyan thong sau: H.263, H.264 (Trong 3GP hoac MP4 container ), MPEG-4 SP, AMR. AMR-WB (3GP container), AAC, HE-AAC (MP4 hoac 3GP container), MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF va BMP; —Hardware support: Accelerometer Sensor, Camera, Digital Compass, Proximity Sensor va GPS; —Multi-touch: H6 trq man hinh cam Cmg da diem; —Multi-tasking: HO trq Ung dung da tic vu; —Flash support: Android 2.3 116 trq Flash 10.1; —Tethering: H6 trq kat n6i interne khong day/co day. 4Itlil it rr M 11114 t I ttltr. Inn n,,(1111 Pik k 111.,21 r I I, 11,1n.rger NI r, t_ri CR morn ‘1,1n,t1r., NIwirrur 11\1. F.112\11 Di/p1.11 I/ her ( nn r 1/ r !I \b one. 11.1‘,/ Ilk I I Iri ktsirrd I NN rl 1/ri%, r t I 11 NI 1114 (111 rt Surface Manager OpenGL ks SC L LIBRARIES Media Frainewoni ErreTypc sSL itcraThit rhr,,,,` virtu, • 2.4. Kier' frac va cac thinh phan trong hg diet' hinh Android M6 hinh sau the hien day dti kien true cac thanh phan ctia he dieu hanh Android. nITI ION. I hm.irl, itnnnu it 'tuck! ION. R Hinh 2.1. Kien Thic cac thanh phan ctia he dieu hanh Android' Linux kernel (nhan Linux) Kernel Linux hoat dOng nhu met lop trim tucmg hoa gifia phan ding va tang clued cua phan mem. Lop nay china tat ca cac thiet bi mitt thap dieu khien cac thanh Oran phan cling khac nhau cua met thiet bi Android. Libraries Libraries bao gem mot top hop cac thu vien lap trinh china ma lenh cung cap nhimg tinh nang va thao tae chinh ten he dieu hanh. Met s6 cac thu vien co ban dtrot liet Ice dtrei day: —System C library — a BSD-derived trien khai cac thu vien he thong ngon ngir C chuan, dugc nhung vao cac thiet bi dua tren he dieu hanh Linux; —Media Libraries — Dua ten PacketVideo's OpenCORE; thu vien nay 118 trg cho viec choi nhac, quay phim, chup hinh theo cac Binh dang file MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG; Theo httpHdeveloper.android.com (trang web chinh than etia Google Android danh cho can nha phat trie'n) 5—Surface Manager — Quan ly truy cap dEn cac he thong con hien thi cling nhu cac lop 6 hoa 2D, 3D tir tang img dung; —LibWebCore — Thu vien dugc dung de to nen thanh phan webview trong Android va c6 the nhung dugc vao nhieu img dung; —SGL — Thu vien ha trg 6 hoa 2D; —3D libraries — Thu vien 6 hga 3D; —FreeType - bitmap and vector font rendering; — SQLite — Mat co se, der lieu nhoi dugc dimg cho cac thiet bi cam tay c6 b45 nha Ilan che. SQLite khong c6 quan he nhu cac cu sty du lieu khac. Android runtime Tai ding mat tang vdri Libraries, Android runtime cung cap mat b0 lei thu vien cho phep cac nha phat trien viet cac img dung Android Wing cach sir dung ngen ngir lop trinh java. Android runtime cling bao gam cac may ao Dalvik, cho phep moi img dung Android chay trong ties trinh rieng cua minh. Dalvik la mat may do chuyen dung dugc thiet ke dac biet cho Android va tai uu hoa cho cac thiEt bi dien thoai di dang yeti gieri han bo nh6 va CPU. Application framework 2.4.3 Android runtime Bing cach cung cap mat nen tang phat then ma, Android cung cap cho cac nha phat trien kha nang xay dung cac tern dung cuc ky phong phi" va sang tat). Nha phat tri'en dugc tir do tan dung cac thiEt bi phin cimg, thong tin dia diEm truy cap, cac dich vu chay nen, thiet lop hE thong bao clang, them cac thong bao de cac thanh tang thai, va nhieu, nhieu hon nao. Nha phat trielt c6 the truy cop vao cac API dugc sir dung beri cac img dung loi. Cac kien trtic img dung dugc thiet ke de don gian h6a viec sir dung Iai cac API. Dua ra nhang Icha !tang Mt& nhau cua he diE'u hanh Android vao img dung de sir dung cluing trong cac ling dung cua minh. Co ban tat ca cac img dung la mat ba cac dich vu va cac hE' thong, bao gam: cac View (la dimg de hien thi thong tin va de ngtrai dung thao tac), Content Provider de chia se du lieu gitra cac img dung, Resource Manager truy xuAt tai nguyen, Notification Manager hien thi cac thong bao, Activity Manager quail 19 chu trinh song cilia ling dung va dieu huOng Activity. 6Applications Tai lop tren ding se la cac ung dvng cho Android (nhu dien thoai, danh ba, trinh duyet,...) cung nhu cac img Ong dugc tai ve va cai dat tir AndroidMarket hay bAt ly img dvng nao ban viet dtrgc tai tang nay. 2.5. Cac khai nRm co ban trong 14p trinh irng dyng Android Activity Met activity the hien met giao dien cth h9a ngtrai dung. Vi du met activity c6 the bleu dien met danh sach cac menu item de ngueri dung c6 the chop Ara co the hien thi anh ding veri tieu de. Met img Ong giri tin nhan van ban c6 the c6 met hoat deng la hien thi met danh sach cac lien he de giri tin nhan tai, hoat deng thin hai la viet tin nhan tai lien he dugc chon, cac hoat deng khic nits IA xem lai tin nhin ca hay thay dei cai dat. Mac du chimg lam viec ding nhau de tao thanh met giao dien ngtrai clang, mei activity dec lap veri nhang cai khac. Mei activity la met lop con dm lop ca so Activity. Met irng dvng c6 the gem chi mot activity hay nhieu activity. Activity chinh phai dugc hien thi d'au tiEn khi kheri Ong chtrong trinh. Chuyen tir met activity sang activity khac bang cach cho activity hien thin khOsi dOng activity ke tiep. Mei activity dugc ve vao met ara s6 tren man hinh, mac Binh se lap dAy man hinh, nhung no có the nho hon man hinh va nam ten cac cira se khac vi du nhu activity thong bao met thong tin gi do. Nei dung trvc quan cua cira se dugc cung cap beri met cay phan cap cac doi tucmg view dan xuat tir lop View. Mei view dieu khien met khoing hinh chit nhat cu the ben trong cira se. View cha chira va to chirc be cvc cac view con. Cac view la ye trong hinh chit nhat ma chimg dieu khien va dap img lai cac hanh Ong ngtreri dung live tiep khoang trong nay. Do do, cac view IA nai ma cac tuong tac dui activity vai ngtrai dimg dien ra. Vi du met view co the hien thi met hinh anh nix) va khei tao met hog deng khi nguai clang nhan vao hinh anh do. Android co met so view da xay citing san ma ban co the sir dvng — gem co cac buttons, text fields, scroll bars, menu items, check boxes... Met cay phan cap view dugc dat trong met cira so dm activity bang phircmg thirc Activity.setContentView(). Content view la dei tucrng View a gec ctia cay phin cap. Class co s& Activity dinh nghia met boat cac sr kien ma dieu chinh yang deli dm met hoat Ong. Class Activity dinh nghia cac sit kien sau day: —onCreate(): Dugc goi khi hoat deng dugc tao ra Ian d'au tien; —onStart(): Dugc goi khi hoat Ong trer nen Win hinh so yen ngueri dimg; —onResume(): Dugc g9i khi hoat Ong bat dAu ttrcmg tic veri ngueri sir Ong; 7—onPause(): Duqc gqi de dimg cac hog Ong hien tai va n6i 14i cac hoat diAng truerc do; —onStop(): Duqc eqi khi hoat dOng khong con hien thi veri ngtreri dung; —onDestroy(): Duqc gqi tnr6c khi hoat dOng bi phi hiiy beri he thOng (bang tay hoac bang he thOng de bao ton b6 nh6); —onRestart(): Duqc gqi khi he thOng da duct dung lai va Ichad dOng lai mot Ian nira. Sau day IA sa do cac su kien trong yang deri caa mgt Activity: onCreate() User navigates to the activity Apps with higher priority need memory onStan() onResum$) AetivItyettoplie Another activity comes into the foreground onPause() The activity is no longer visible onStop() onRestart() User returns to the activity User navigates to the activity The activity is finishing or being destroyed by the system onDestroya Hinh 2.2. Yong c of cita mot Activity' = Theo http±develoner.android.com Wang web chink tithe cua Google Android danh cho cac nha pilot trien) 8Service MEt service khOng co giao din true quan, no tren nen trong mot khoang thai gian khong xac dinh. Vi du mEt service co the choi nhac nen, hay no nap du liEu ten mang hay tinh toan cai gi do va cung cap kEt qui cho activity can dEn no. MEi service ma rung to lap ca so Service. Trong khi ket no', ngueri str dung co thE giao ti6p yeti service thong qua giao din ma service d6 trtmg ra. Vi du nhu trong service choi nhac. giao din nay co thE cho pile!) ngueri dung pause, rewind, stop va restart lai playback. GiOng nhu cac activity va cac thanh phan khic khac, service chay trong thread chinh cda tiEn trinh irng dung. Vi thE cluing khong thE chan nhcrng thanh phan khac hay giao din ngueri dung, chUng thuang tao ra cac thead khac cho cac nhiEm vu hao ton thai gian.So do cac str kion trong wing doi cua mot service: (7- Call to Call to startService0 bindServiceO • onCreate() onCreate() onStartCommand() Server running 1 The services is stopped by itself or a client onBind() 7—Clients are bound to service All clients unbind by calling unbindSenice0 onUnbind() onStartCommand() onDestroy() Unbounded Bounded service service Hinh 2.3. Viing doi ciia mot Service 9Content provider Mot content provider tao ra mot tap et' the cac act lieu coa img dung kha dung cho cac (mg dung khac. Da lieu do the duce km tit trong he thong file, trong It* co sa da lieu SQLite, hay trong mot each khic nao do. Content provider ma rOng 16p co se ContentProvider de cai clAt mot tap cac chuan cac phuong thirc cho phep cac img dung khac dat duqc va luu tril du lieu dm kieu ma no dieu khien. Tuy nhien, cac img dung khong g9i trot tiep cac phtrong thirc nay, chimg sir dung mot d6i tucmg ContentResolver va goi cac phuong thirc cua no. MOt ContentResolver do the not chuyen veri bit cu content provider nao, chung Ong tic vei provider de quan 19 giao tiep lien tin trinh. Broadcast Receive MOt Broadcast Rreceiver la mot thanh phan khong lam gi nzoai viec nhan va dap lai cac th6ng bao broadcast. Nhieu broadcast kheri (tau trong ma M thong - vi du nhu thong bao mai gier thay dol. pin you, anh da duqc chup. hay ngueri dung da thay dal noon Cac img dung co the tao ra cac broadcast, chang han de Ung dung khac blot dugc mot se; du lieu da duqc tai ve thiet bi va sari sang cho viec sir dung chimg. Mot img dung co the co mot so Broadcast Receiver de dap lai bat cir thong bao nao ma no cho la quan tong. Tat ca cac receiver ma rong to lop cu so BroadcastReceiver. Broadcast Receiver khong hien thi mot giao dien ngtre6 dung. Tuy nhien chting co the bat dau mot activity d dip lai thong tin ma chitng nhan, hay chimg c6 the sir dung NotificationManager de canh bao ngueri dung. Notifications co the lay su chit 9 dm nguai dung bang nhieu each, 16e sang den sau, rung, tao ra am thanh, van van. Chang thuemg lay mot bieu tugng ben yang trong thanh trang thai, cai ma ngtreri dung c6 the my de lay th6ng diep. View Trong mot Ung dung Android, giao dien ngueri dung duqc xay dung tir cac d6i tucing View va ViewGroup. Co nhieu kieu View va ViewGroup. M8i mot kieu la mot con dm class View va tat ca cac kieu d6 duqc g9i la cac Widget. Tat ca m9i widget deu co chung cac thuOc tinh co ban nhu la each trinh bay vi tri, background, kich thu6c, le ... TAt ca nhang thucic tinh chung nay duqc thE hien het a trong dai tirqng View. Trong Android Platform, cac screen luon dtrqc be.) tri theo mot kieu cau trite phan cap nhu hinh clued. MOt man hinh la mot tap hqp cac Layout va cac widget duqc be) tri co thir nr. DE the hien mot man hinh thi trong ham onCreate ctia m6i Activity can phai duce goi mot ham la setContentView(R.layout.main); ham nay se load giao dien to file XML len de phan tich thanh ma bytecode. 10Intent: {action + data + requestCodelD } requestCodelD resultCode Optional data Hinh 2.5. Intent View Group I View Group Vier View J View View View Hinh 2.4. View Intent LA cAu not giCia cac Activity: Ung dung Android thutng bao gom nhieu Activity, m6i Activity host dOng dOc lap voi nhau vi thut hien nhane ding viec khac nhau. Intent chinh IA ngueri dua thu, giap cac Activity co the trieu goi cling nhu truyen cac du lieu can thiet tai mOt Activity kW. Dieu nay cling giong nhu viec di chuyen qua lai giaa cac Forms trong lap trinh Windows Form. 112.6. Cie thanh phan trong m*t project &lig dyng Android AndroidManifest.xml Trong bat ki mOt du an Android nao khi tao ra dau c6 mot file AndroidManifest.xml, file nay duce dung 6 dinh nghia cac man hinh sir dung. cac quy'en cling nhu cac giao dien cho irng dung. DOng thin no ding china thong tin ‘e phien ban SDK cling nhu man hinh chinh se chay dau den. Vi du file manifest: mr.1 version="/.0" encoding= "ittf-8"?- <manifcst xmlns:android="http://schemas.android.com/aplc/res/android" package="com.example.example 1" android:versionCode="/ " android:versionName="/. 0" <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="9" > <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme= "Cvstyle/AppTheme" > <activ ity android:name="com.example.examplel.MainActivity" android:label="@string/apprzame" <intent-filter:> <action androidmame="androictintentaction.MAIN" <catctiory android:name="androidintentcategoty.LAUNCHER" =-• </intent-filter> </act ivitv> </application> </manifest> 12File nay dugc to deng sinh ra khi tao met du an Android. Trong file manifest bao gig cling c6 3 thanh phan chinh do la: application, permission va version. Application: china cac gia tri dinh nghia cho mot img dung Android nhu icon,ten Ung dung, chE de hien thi giao Ngoai ra can phai khai bao cac Activity va Service co trong chucmg trinh tai day. Permission: bao gem cac thuoc tinh chi dinh quyen truy xuat va sir dung tai nguyen cua img dung. Khi can sir dung met loai tai nguyen nao do thi trong file manifest cua img dung can phai khai bao cac quyen truy xuAt tuong img. SDK version: Mc dinh phien ban SDK nh6 nhat ma img dung hien dang sir dung tuong ung veri mot phien ban he dieu hanh Android ma img dung c6 the tuong thich. File R.java. File R.java la met file to dOng sinh ra ngay khi tat) irng dung, file nay dugc sir dung de quan ly cac thuec tinh dugc khai bao trong file XML cim img dung va cac tai nguyen hinh anh.MA nguen cila file R.java dugc to (Jong sinh khi co bat ki met sg kien nao xay xa lam thay dei cac thuec tinh trong img dung. CO the n6i file R.java hoan toan khong can phai dung cham gi den trong ca qua trinh xay dkrng img dung. Thu glue src. La vi tri china g6i cac class trong img dung. Cac class c6 the la cac met Activity hoac Service hoac cac 16p cluirc nang nao d6 dugc viet bang ngon ngil Java dua tren API dugc cung cap sAn dm Android. Can phai co it nhat met Activity va khai bao la Activity chinh de chucmg trinh c6 the chay dugc. Thu muc rec Thu muc chira tai nguyen img dung. Thu muc nay bao gem 5 thu muc con la: drawable — hdpi, drawable — mdpi, drawable — Idpi, layout, values. Drawable — hdpi, drawable — mdpi, drawable — ldpi la ba thu muc dung de chira cac hinh anh dirge sir dung trong qua trinh thiEt ke giao dien img dung, bao gem ca icon cua img dung. Ba thu muc tuong img \Teri hinh anh se dugc sir dung o ba de phan giai khac nhau Ian lugc la: cao, trung binh, thap. Dieu nay gitip cac nha lap trinh co the thiet Ice giao dien img dung phi' hgp vgi nhieu do Olin giii man hinh tuong thich yeti nhieu loai thiEt bi. Thu muc layout china cac file xml dung de khai bao va thiet ke giao dien cho met Activity hay met thanh phan dieu IchiEn con trong tern dung Android. 13Thu muc values gOm cac file xml chira cac gia tri chuOxi. ma mau Gap ngueri lap trinh có the a dang thay doi nhang gia tri nay trong img dung mo.t cach nhanh chong ma khong can phai sera trong code cua img dung. 14CHIXONG 3. CONG NGHC PUSH NOTIFICATION VA SERVICE TRONG ANDROID 3.1. Gifri thi0 14 citing nghe Push Notification 3.1.1. Tang quan GCM cho Android la met dich vu mien phi grit', nguiri Oat trien phAn mem giri du lieu to may chit den Ung dung Android tren thiet bi Android, va thong diep ngtroc lai tir thiet bi den cloud. DO cep the la thong diep nhe "noi veri" img dung la c6 dir lieu meri vim duce tai vE tir may chic. hoc no co the la thong diep co dung lucmg len tai 4KB. Dich vu GCM xir ly tat ca cac khia canh cila hang do' tin nhin va cung cap den img dung dich tren mot thiet bi dich. Cac dac diem chinh cua GCM: —Cho pile') img dung server ciia ben thir 3 gUi thong diep den img dung Android cua ho; —Sir dung GCM Cloud Connection Server, co the nhOn thong diep ngucrc lai tir thiet bi cua ngutri dung; —Lrng dung Android khong an chay lien tue de nhOn thong diep. He thong se to "danh thin" img dung thong qua Intent broadcast khi thong diep den, mien la img dung ducrc cho phep va thiet lOp vei broadcast reciver thich hop; —GCM khong cung cap bat kY met giao dien ngueri dung hoc cac xir 19 khac del veri thong diep hoc 61 lieu; —GCM chi don gian gin thing du lieu the nhOn dirge den img dung, img dung se co day chi cac kha ning de xi" 19 no. Vi du, cac img dung c6 the giri thong bao, hien thi met giao dien ngueri clang, hoc am tham deng bo der lieu; —Yeu cAu thiet bi chay Android 2.2 hoc cao hon va da cai img dung Google Play Store, hoic met gia lop chay Android 2.2 veri cac API ctia Google. Tuy nhien, ban khong bi gi6i han viec trien khai img dung oh ban thong qua Google Play Store. NO sir dung met kEt n6i hien tai cho cac dich vu cua Google. Cho cac thiet bi tit 3.0, dieu nay den h6i ngtrei dung thiet lop tai khoan Google cua ho troll cac thiet bi di deng elm he. Met tai khoan Google Bong phai la met you au tren cac thiet bi chay Android 4.0.4 hoc cao hon. 153.1.2. Thu0 ngfr va khdi nifm liin quan Bang sau torn tat cac thuat nger chinh va khai niem lien quan trong GCM. N6 dugc chia thanh cac danh muc: —Components (thanh phan) — cac d6i tugng chinh trong GCM; —Credentials - cac ID va the dugc sir dung trong cac giai clop khac nhau ciia GCM de dam bao rang tat ca cac ben dA dugc xac thuc, va thong bao do la di den dia diem chinh xac. Components Client App GCM cho phep frng dung Android clang chay tren mOt thiEt bi. Day phai la mOt thiEt bi Android 2.2 co Google Play Store dugc cai clat, va no phai co it nhat mOt clang nhap tai khoan Google nett thiEt bi dang chay ni0 t phien ban thap horn so vdri Android 4.0.4. Ngoai ra, 6 thir nghiem, ban co the sir dung mOt trinh gia lap chay Android 2.2 vdri cac API ctia Google. 3rd-party Application Server MOt may chit ting dung ma ban vtet nhu la mOt phfin cua viec thgc hien GCM. Cac may chit img dung cfm bEn thin 3 giii du lieu den mOt i.rng dung Android tren dien thoai thong qua may chit ket not GCM. GCM Connection Servers Google-cung cap may chti co lien quan trong viec thgc hien cac tin nhan tir may chit ang dung dm bEn thin 3 va gfri chting vao thief bi. Credentials SenderlD S6 cua du an ma ban co dugc tir giao dien diEu khien API (khi clang k9 Crng dung tren Google APIs Console. SenderlD dugc sir dung trong qua trinh clang k9 de xac dinh mOt may chi, ling dung ben thir 3 ma dugc phep girl tin nhan den thiEt bi. ApplicationID l:ing dung Android dugc dang k9 de nhan tin nhan. Cac ling dung Android dugc xac dinh bang ten g6i tir mainifest. DiEu nay dam . bao rang cac thong diep dugc nham muc fiEu den cac img dung Android chinh xac. RegistrationID MOt ID do cac may chit GCM cho cac img dung Android cho phep no nhan tin nhin. MOt khi img dung Android c6 registrationlD, no 16se giri no den may chit img dung ctia bEn thir 3, GCM sir dung no de xac djnh timg thiet bi da dang Icy de nhan tin nhan cho mot img dung Android that djnh. Noi each khac, mot registrationlD dugc gin ved mot img dung Android dac bier chay tren mot thiet bj cu the. Luu .$: Neu sir dung sao ltru va phuc h61, nen tranh sao km ID clang kY. Khi sao kru tit mot thiet bj, img dung sao km chia se Prefs bira bai. Neu ban kitting loaf tilt mot each r6 rang GCM registrationlD, no co the dugc tai sir dung tren mot thiet bj m6i, trong do se gay ra 161 chuyen giao thong diep. Cho GCM de lam viec, cac thiet bi di dOng phi bao Om it nhat Google User mot tai khoan Google neu thiet bj dang chay mot phien ban chap Account han so ved Android 4.0.4. MOt API key dugc Itru tren cac may chti irng dung cita ben thir 3 Sender Auth cung cap cho cac may chit img dung cho phep truy cap vao cac Token dich Nit, dm Google. API key dugc bao g6m trong lieu de ciia cac yeu cau POST de giri tin nhan. 3.1.3. Kiln Ink tang quan Viec trien khai GCM bao gom mot may chit cua Google cung cap ket not, may chit img dung ben thin 3 ma tucrng tac yeti cac may chit ket n6i, va mot img dung client GCM cho phep chay teen mot thiet bi Android: ling dung tai thiet bi Crng dung may 4 Chu ben 3 Ket nei may chit GCM Hinh 3.1. Kiln Thic tang quan GCM' 3 Theo hup: developerandroid.com (trang web chinh thirc cna Google Android danh cho cac nha Sat tri 'en) 17Cac thinh phan arcing tic: —Google cung cap may chit kat n6i GCM nhan tin nhan to mOt may chit Cmg dung cita ben thir 3 va giri cac tin nhan clan mOt img dung Android GCM cho phdp (cac "img dung khach hang") dang chay ten mOt thiet bi. Hien tai, Google cung cap cac may chit kat not cho HTTP va XMPP; —Cac may chit irng dung cita hang thin 3 la mOt thanh phan ban trian khai de lam viac veri may chit kat not GCM dugc Iva chon. Cac may chit Ung dung giri tin nhan den mOt may chit kat not GCM; cac kat not may chit xep vao hang dqi va luu tni cac tin nhan, va sau do girl no den thiat bi khi thiat bi dang true tuy6n; —fing dung khich la mOt ling dung Android GCM cho pile!) chay trait mOt thiat bi. Da nhan tin nhan GCM, img dung nay phai dang 14 veri GCM va co dugc mOt registrationlD. Neu dang sir dung (CCS) may chit ka not XMPP, cac (mg dung khach hang co the giri "ngugc dung" tin nhin lai cho may chi, kat n6i. 3.1.4. Chu trinh vbng dog —Kich float GCM - MOt img dung Android chay tren mot thiat bi di dOng dang ky de nhan tin nhin; —Giri tin nhan - MOt may chit ting dung cua ben thir 3 se giri tin nhan den dien thoai; —NhAn mOt tin nhan - Mt5t irng dung Android nhan dugc mOt tin nhin tit mOt may chit GCM. MO to chi fiat qua trinh: Kich hoat GCM: Lan dau tien Cmg dung Android can sir dung dich vu nhan tin, no ggi phucmg thee GoogleCloudMessaging register(). Phuang thirc d6 tra ve mOt registrationID. Cac Cmg dung Android nen luu tit ID nay de sti dung va sau (vi du, de kiam tra trong onCreate() nau no da dugc dang k9). Giri thong diap: Day la trinh to cua cac sir kien xay ra khi mOt img dung may chit gin mOt thong diap: —Cac may chit img dung gui tin nhin den cac may chit GCM; —Google enqueues va luu tru cac tin nhan trong twang hop thiat bi dang An; —Khi dien thoai tut tuyan, Google se gui tin nhan teri cac thiat bi; —Tren thiat bi, he thong cac chircrng trinh Oat song tin nhin tea cac ling dung Android dugc chi dinh th6ng qua quang ba Intent vei cac diau khoan thich hop, de chi nhcmg img dung Android nham muc lieu dugc thong tin. Dieu nay dinh thee cac img 18dung Android len. Cac (mg dung Android khong can phai dugc chay Mu& de nhan duce thong bao; —Cac Ung dung Android xir 19 thong bao. Neu ting dung Android dang lam gia tong khong tam thuerng, ban có the muOn My mot PowerManager. WakeLock va lam bat cir xir 19 trong met dich vu; —MOt Ung dung Android co the hily clang k9 GCM neu no khong con mtban nhan tin nhAn. Nhan thong diep: Day la chai cac su kien xay ra khi mot img dung Android dugc cai dat tren thiet bi di dOng nhan dugc tin nhin: —He thong nhan dugc cac tin nhin giri den va chiet xuat cac cap key / value din lieu tho tir tin nhin neu can thiet; —He thong chuyen cac cap key/value den Ong dung Android dich thong qua Intent com.google.android.c2dm.intent. RECEIVE; —Ling dung Android chiet xuat du lieu the) tir Intent c2dm thong qua cac key va xir 19 du lieu da dugc chiet xuat. 3.2. trng dyng Push Notification trong Ling dyng Android 3.2.1. Sc do tang quan cac but trong qua trinh giii nh4in tin hilt' I database server mobile 0 CD) 0 GCM Ilinh 3.2. Sa do tong quan cac but trong qua trinh girl nhcin tin hieu4 Theo htlp::ideveloner.andwid corn Wang web chinh thirc dia Google Android dinh cho cac nha ph& trie'n) 19—Buck 1: Thiel bi Android girl Sender ID va Application ID den may cho GCM de clang Icy; —Buerc 2: Thiet bi nhOn lai RegistrationlD to GCM server; —BIS 3: Thiet bi gui yeu eau den may chit img dung cal RegistrationID kern theo; Bu6c 4: May chit irng dung giri tra du lieu co RegistrationID kern theo cho may chit GCM; —Burk 5: Thiet bi nhOn du lieu duce gui ve to may chit' GCM. 3.2.2. Thwc hiOn (hilt lop Push Notification cho frng dyng Android DAng ky dich vu GCM GCM — Google Cloud Message la met dich vu cho pile!) girl dit lieu tie server den thiet bi Android va cling cep the nhon dupe thong diep tie thiet bi veri ding kieu ket n6i. De c6 the sir dung dich tip nay, can pita' dAng k9 dich vii vi thiet lop thong so voi Google API. —Tao Google API project +Truy cap vao trang https://code.google.com/apis/console; +Neu chua c6 API project, se co thong bao to meri; +Google se cung cap so hieu project, luu lot so nay vi no duce dung sau nay. —BOt dich vu GCM +d trang chu ctia Google APIs Console, chop Services; +Chuyen Google Cloud Message sang the de ON. Lay API key +Trong chinh trang dieu khien Google API, ch9n API truy cap. Ban se they met man hinh tucmg to nhu sau: GO- a DIE. OCII Tilt Omen, Sara TWA API beasts RUPOIN CPICAS API Access to Drat Pea Sane Olt':: Ina or API moats Le. rig a ram OALTI lace Ae1kcy Authorized API Access 7; tot JIzta-:: • vv. y ILar Jrcr: Create an OAuth 20 client ID Simple API Amon Jsc ker. to act rt, you pqect Ater yo] m roc rat to aces: user it Lran- it= acute t1Pb 8Crear . Cane liar Maar key . 20+ NhAp vao Create new Server key va Itru API key nhan dugc. Thiel lap tren img dung Android GoogleCloudMessaging API la mot b0 this vien dm Android cho pile!) cung cap cac chat nang nhan thong diep to GCM Server ctia Google. De girl hoac nhan tin nhin, ung dung dAu Wen can phai co dugc mot RegistrationlD. RegistrationID xac dinh cac thiet bi va irng dung, va cung có the xac dinh may chti img dung ctla ben thlr 3 dugc phi!) girt tin nhAn ting dung nay. De có dugc mot RegistrationID, ban phai cung cap mot hoac nhieu SenderlD. MOt SenderlD la mot con s6 chr an ma ban co dugc to giao dien dieu khien API — chinh la API key lay dugc a tren. SenderlD dugc sir dung trong qua trinh dang kY de xac dinh mot may chit img dung dm ben thir 3 duct phep giri tin nhin den dien thoai. Doan code sau day cho thay lam the nao de goi phucrng thirc register() de lay duct duct ResgistrationiD: String SENDER_ID = "My-sender-ID"; GoogleCloudMessaging gcm = GoogleCloudMessaging.getlnstance(context); String registrationld = gcm.register(SENDER_ID); De nhan tin nhin cita GCM, can phai khai bao mot skr cho phep (permission) va mot BroadcastReceiver trong file manifest.xml. De cho phep cac ting dung sir dung GCM, them permission vao manifest.xml: <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> GCM mang lai tin nhan nhu mot ph& song (broadcast). Ngtreri nhan phai clang lc)) trong tap tin manifest de clanh thirc img dung. <receiver android:name=".gcmUtilities.GCMReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="YOUR_PACICAGE_NAME" /> </intent-filter> </receiver> 21Service teen Android Nthr da trinh bay so qua a phia tren ve Service tren Android, trong phan nay chimg tin mu6n trinh bay ra- hon ve Service tren Android — thanh phan quan trong cim img dung se xay dung. Service la mot thanh ph5n cua ang dung Android dung de thuc thi mot phan tic vu ngam ben dueri nen va kh6ng co giao dien hien thi not dung. Service cling giong nhu cac thanh phan khac cua ang dung (Activity, BroadcastReciver...), no se chay tren luing chinh cua tien trinh ma ang dung dang chay tit do. Dieu nay co nghia la neu img dung can thuc hien mot ding viec nao do Mn nhieu then gian nhu choi nhac, tai du lieu to tren mang va thi can phai dua ding viec do vao men lung rieng da thus thi. Viec nay se tranh cho cac ding viec dang thuc thi tren bang chinh khong bi gian doan. Chang to can xac dinh re cac die tnrng cin Service: —Mot service kliiing phai mot tien trinh tach biet. MOt d8i tugng Service kh8ng he chay tren tien trinh cua rieng no ma no chay tren tien trinh cua ang dung; —MOt service khong phi' la min !thing. Dieu nay c6 nghia la mai cong viec se dugc luting chinh thuc thi. Chinh vi v5y mot din tugng Service thutmg dinh nghia mot Wang cim rieng no de thuc hien cac cong viec nhim trinh tinh trang gian doan cac ding viec dang thus thi a 1u8ng chinh. Min Service co the dirge sir dung theo hai cach: —Min Service co the dugc dimg de thuc thi mot ding viec dual nan ma klthrig can hien thi giao dien ngueri dimg. Loai service nay dirge bit dau va duce cho phi!) hoat dOng cho den khi min nguiri nao d6 dirng no lai hoic no to ngit. O the do nay, no dugc bat dau bang each gal Context.startService0 va dung bang lenh ContectstopService0. MOt Service c6 the to ngit bing lenh Senice.stopSelf0 hoc Service.stopResulf0. Moi Service chi co mot the hien duy nhAt, do d6 chi can mot lenh stopService0 de ngimg mot Service lai cho du lenh startSenice0 co dugc gal ra bao nhieu Ian; —Mot Service con c6 the dugc sir dung de cung cap mot tinh nang nao d6 cho img dung khac ket nai va sir dung. MOt env dung co the thiet lop mot duerng truyan tai den Wang Service va sir dung duang ket nei de de dieu khien Service. Ket not nay dirge thiet 15p bang cach gal lenh ContextbindSenice0 va dugc thing bang each g9i lenh ContextunbindService0. Nhiau img dung co the ket not ted ding mot den tugng Service. Neu Service dugc mot img dung khach ket n6i den van chua dugc kheri chay thi lenh bindService0 co the thy 9 kheri chay no. Hai chE do nay thi khong tach biet town bo. Ban co the ket not voi mot Service ma no da dugc khan chay yeti lenh startService0. 22o-S art() rti s rvIning The service is stopped (no callback) Service is crested by bkidService0 Service Is started by stariService() Client interacts Ann the service onCreate() orCreatell Hinh 3.3. Vong dal ctia mot Service Dua vao lugc (la trEn to c6 hai wing lip quan tong trong vOng deri cua mot dad tugng Service cue b0: —Vong ddi toan din(entire lifetime): bit dAu tir 16c goi phuong thirc onCreate9 den lac goi phuong unix onDestrovo. Cling giOng nhu Activity, d6i tugng Service se khoi tar) cac gia tri tai phuong thirc onCreate0 va don del) b0 nher tai phuong thirc onDestroy(); —Wing deri thuc thi (activce lifetime): bit dAu tir lik goi phuong thtk onStart0. Neu mot d6i tugng Service cho phap mot Cmg dung !chic ket not den no thi no phai cai dit 03 phuong thirc sau: —Ibinder onBind (Intent intent): Khi mot d6i tuerng mu6n tao ket not den mot doi tugng Service thi no se ggi phucmg that Context bindService(...) va giri di mot doti tugng Intent. Phuong thirc onBind( se duce goi de sir 19 yeu cAu kat not nay. NO se tra va cac kenh giao tipma d6i tugng can kat not co the sir dung de tuong tic veri Service; —Boolean on Unbind (Intent intent): Phtrong thirc nay turmg tunhuphtrang thirc onBindO. Tuy nhien no se dirge ggi khi co mot d6i tugng ggi phuong thirc ContextunBindServiceo de ngat 23ket not v6i Service. Lac nay phtrcmg thirc onUnbind() se doge pi de xir ly yeu eau ngat ket not den Service; — Void onRebind (Intent intent): Phucrng thirc nay duce goi khi c6 mot d6i tugng khach meri muOn kat not clan Service. De kited chay service, c6 hai chat clO do the them vao qua trinh duce quyet dinh khi chay, thy thuOc vao gia tri tra ve tir ham onStartConunandO: START_STICKY dugc sir dung cho cac dich vu dugc bit clAu mot each re rang va dime lai khi can thief, tong khi START NOT STICKY hoc START REDELIVER INTENT dugc sir dung cho cac dich try ma chi nen duy tri hoat dOng trong khi xu ly cac lenh gtii cho service. Hing s6 dugc tra vat tir onStartCommand (Intent, int, in0: nett qua trinh cila service bi dung lai (killed) tong khi no dugc bit (tau (sau khi tra ve tir ham onStartCommand (Intent, int, int), sau do dua service vat tang thai dA bit dAu nhtmg khong giu lai nhUng intent da cung cap. Sau d6 he thOng se cif) ging de "tai taco" dich 24CHUONG 4. XAY MING I:ING DUNG NHAC LICH THI CHO SINH HEN THANG LONG 4.1. Tang quan yeu au he tilting 4.1.1. Mo tit Hien nay, sinh vien Thang Long cop nhat lich thi cita minh ten trang web cila nha twang. M6i khi c6 lich thi, trang chit website caa nha twang clang thong bao cho sinh vien toan twang duqc biet da co Itch thi men. The nhung hien nay, he th6ng clang k9 hpc online cita nha twang thuerng xuyen bi qua tai do lugng sinh vien truy cap qua Ion, cling vad viec thong bao tren website bat buoc sinh vien phai theo d6i vi cop nhOt lien tuc thong tin qua mpg da gay nen nhang kh6 khan cho nhieu sinh vien nhu kh6ng the truy cop intemet, may chit nha trtremg khong hog dOng. lich thi c6 nhOng thay d6i ma sinh vien khong chit 9 se khong cap nhat kip thai. Sinh vien phai cep nhieu bien phap de kru tit lich thi nhu chap tay, ltru vao may tinh, dien thoai dudi clang tap anh, tap van ban. Do vay, nh6m tic gia thkrc hien de tai mong mu6n ph& trien mot (mg dung di dOng nharn muc dich quan ly va cap nhat lich thi cua sinh vien sao cho dat hieu qua cao nhAt, han chE rut ro xay ra trong khi ki thi dien ra. Nit nha cho sinh vien biet lich thi ctia cac mon thi sip tOi giup sinh vien tranh duqc tinh tang "quen di thi". Hifn trang tai triton Hien tai thi viec xem va cap nhat Itch thi cua sinh vien Dai hpc Thang Long dien ra mot cach thit cong, van thuemg xuyen xay ra cac skr co khiEn cho sinh vien khong thE theo dei lich thi cua minh. 4.1.3. ren cdu nghifp vy BR1:Cap nh(it lich thi Lich thi se duqc cap nhat dam bao Itch thi duqc tra ye la lich thi hpc kjf gAn nhAt ctia sinh vien. Bat kS, mot su thay d6i nao ve Itch thi se duqc thong bao cho sinh vien. BR2:Hien thi lich thi He thong giup sinh vien co the theo doi lich thi ctia minh mot each chi tiet nhAt, cac mon thi duqc sap xetp theo thin tkr that gian gitip cho sinh vien thu xEp duqc thai gian hpc rap. BR3:Lich thi dtrqc luu tru teen CSDL Khi lich thi mdi nhat duqc he th6ng cop nhat, lich thi dO se duqc ltru tru Lai vao co set dir lieu dm thiet bi. Gift!) cho qua trinh theo dOi Itch thi cita sinh vien Bang bi gian (loan net he th6ng cua nha twang xay ra skr co. 25Cpang xuat) z BR4:Nhie lich thi Khi co mat mon thi sap bit dAu, he thong se hien thi thong bar) de sinh vien biet ducc mon thi gan nhAt ctla minh la gi. BR5:Tuy chop thiri gian cap nhOt, nitie lich thi He thong cho phep ngueri dung c6 the tuY chop thai gian cop nhOt lich thi hoac thCri gian nhac lich thi. 4.2. ling dung Android 4.2.1. Mb td Day la ung dung phia ngueri dung (client) duct Oat trien nham thong bao, hien thi, luu tni du wou ve lich thi, clang fired nhic niter lich thi cho sinh vien. 4.2.2. Se do tang quan Sc chic ming chinh cda ing (king Dang nhap 4.2.3. Cdc tdc nhan tham gia Ngtroi dung: la nguCri sir dung img dung Din thiet bi Android, ngueri clang c6 the cap nhot lich thi hoac xem Lich thi sau khi dang nhap vao he thong. 4.2.4. Cdc chic nang chinh clia ing dyng Bang nhOp: ngtrai dung can phai clang nhOp vac, img dung sir dung ma sinh vier, &roc cap bed trutmg Thang Long. Iling yeti moi ma sinh vien se c6 ducc lich thi ttrcmg img cita sinh vien 26Bang xuat: ngueri dung khi kh6ng math nhan thong bao hoac cap nhat lich thi co the sir dung chile nang clang xuAt de hily clang kY m5 sinh vien veri may chil he thOng. COp nhOt lich thi: chirc Wang nay dugc sir dung khi ngithi dung cai dat the dO cap nhat bang tay, ngueri dung se chit Ong kiem tra cap nhat bang viec thao tac tnrc tiep yeti Ung dung. Neu ngueri ding chip the di) cap nhat tu eking, chirc 'tang nay se An di va dugc chay tv dOng ma kh6ng can thao tac truc tiEp voi img dung. Cal (14t thiri gian cap nh4t: chtic nang nay cho phep ngueri clang thy chinh vE khoang th6i gian Ung dung kiem tra cap nhat lich thi veri he thOng may chit. CAi cl4t thiri gian nhic lich thi: chirc nang nay cho phep ngueri dung thy chinh vE khoang thai gian nhic nher tnrerc ngay thi &Si yen tn6i mon thi. Den dimg that gian dugc cai dat, neu co mon thi sap dien ra, ung dung se thong bao tai ngueri clang. 4.2.1 CU that the chinh Thtec the mon thi: Mot mon thi deu co cac thuOc tinh: ma mon. ten mon, ngay thi, ca thi, pheng thi, tinh tang. Thvc the lich thi: Lich thi gom nhieu mon thi dugc sap xep tang &An theo ngay thi. Thwc the Itch nhiic nhfr: Danh sach cac thong bao nhac nh6 ye mon thi. 4.2.6. Mk td cdc chat nang ciia zing dyng UC #1 DANG NHAP DO phirc tap: Low MO to Chirc nang nay cho phep ngtrgi dUng clang nhap vao img dung, img dung se clang k5, ma sinh vien cira ngutri dung vet he thong may chit. Tac nhan Chinh Ngueri dung. Phu Kitting. Tien dieu kien ling dung kheri chay khong c6 176i, thiet bi c6 ket not Internet, chua c6 ma sinh vien nao tru6c d6 dang clang nhOP. , HO dieu kien Thinh cling Ngutri clang dang nhap dugc vao img dung, ma sinh . vien Registration1D dugc dang 14 veri may chit. LOi Nguai clang kitting dang nhap dugc vao img dung, tang that img dung khong thay doi. 27DAC TA CHI:IC NANG Lung sir kiln chinh / kich ban chinh Chirc nang nay bit Tau khi ngtrai thing ma ting dung vi chua c6 tai khoan nao dang truy cap: I. He th6ng you cau mural dung nhap vao ma sinh via; 2.Ngueri dung nhap ma sinh via; 3.ting dung My RegistrationiD va ma sinh vien ngtrai (king vita nhap girl len he dieing may chit: 4.ling dung chuyen vac) giao dien chinh. Lung sir kien Oat sinh / kich ban phat sinh Neu till& bi khong ducrc ket n6i Internet, ting dung se thong bao 161. Ngueri (king c6 the dong ung dung hoac bat ket not Internet de tiep tvc. Sa dli hanh dOng (Activity diagram) Khong 0 (Nhap ma siih vier) 4 o (ay RegistrationIC) ket itemet o not Icho Co (Gui thong to dang nhap den rrey ch) W (Dang nhap thanh cong) 28Cac yeu eau d5c biet kit Kh6ng co. Tinh tang tar& khi thgc hien use-case U'ng dung a the di ch6 dang nhap. Ngueri dung khong sir dung duce chirc Jiang nao khac. Tinh tang sau khi thtrc hien use-case - Neu long nhAp thanh ding, giao dien chinh dm irng dung &roc kich hoat. Thong tin clang kY yeti may chi ducic ghi nhan va km trO. - Neu dang nhap that hal, Ong dung th6ng bio NIA khong c6 gi thay dei. THIET ICE UML Sadie) lop phan tich (Analysis class diagram) 0 1 - Server Utility XII no* X User Gies dies dang nhap GO4 Service May chi' ung dun 29«con rot» GCSI Service +Lay RegistratbnIDO 0 x User «boundary» Giao then dung nhap «control» Xu ly Login +Dang nhap() +Lay RegistratrionIDO +IGemtra ket nol rreng() «control» Server Utility +Dang nhap() «boundary» May chu ung dung So di trinh ttr (Sequence diagram) 0 «boundary» Gan din ciao; nt011 «control» iktilagia «control» :JiCtiSteite «control» " eryprIISy «boundary» _Ltlay rhn Imo dia 3 : Dang nhap() 11J 4 : Lay Regstra Tra ye RegStrabonIDO 6 : Deng nhap() 7: Dung tap() So da lap chi hit (Class diagram) 30Ntri11.7-v<rs- lichthitltis THANG LONG UNIVERSITY ! vier) DEng nh4p L 31UC 412 RANG XUAT DO phut tap: Low Mo ta Chirc nang cho pile', nguer. dung clang xuet ra kh6i wig dung. Tac nhan Chinh Ngueri dung. Phu 'Chong co. Tien diets kien Ong dung kheri chay kh6ng c6 161, dang cep tat khoan clang nhip wig dung. HO dieu kien Thanh Ong Ong dung trey ve man hinh dang nhip, the thong tin dtmc lira tril tren thiet bi dm ngueri dung tnrec bi x6a136, ma sinh vien tnrerc dtrot x6a khoi he thong may chit. L61 Ong dung kitting thay dtoi trang thai. DAC TA CHOC NANG Luting str kien chinh / kich ban chinh Chuc nang nay bit dau khi ngueri dung chcon chirc nang "clang xuat": 1.Ong dung xoa cac thong tin km tra dm nguari dung; 2.Ong dung gin thong bac) clang xuet den may chit; 3.Ong dung trier ve chtic nang dang nhip, ma sinh vien dtroc )(ea b6 tren may chit. 32So 6 hanh dOng (Activity diagram) 0 1 < Menu chinh ) / along co Chon nut dang xua) Internet Co dang xua) Co ket not khong (Gui yeu cau (Xoa thong in seih vie) I Co ve giao den dang nhar) Lueing sir Icien phat sink / itich ban phat sinh Khong co. Cac you cau ac biet khac Kh6ng co. Tinh Wang Mr& khi thirc hien use-case Ngutri dimg dang (tang nhap vao Cmg dung. 33Tinh tang sau khi thuc hien use-case 1.Neu use-case thuc hien thanh ding, img dung se- trer ve man hinh clang nhap. MA sinh vien duce xoa bo khdi may chu. 2.Use-case thuc hien khong thanh ding. trang thai ung dung khong thay doi. Diem ma rang !Chang có Thief ke UML Sa M lop phan tich (Analysis class diagram) a A K- ___>. ( < r Server Utilities I Database 1 7---<- Xu ly dang xuat I SessionManager \... y ______> Flat dans xuat User May chu ung dung 34«boundary>> Nut dang xuat «control> > Server Utilities Database «control» Xu ly dang xuat +Logout° +Xoa du feu() «control» SessionManager +Xoa M3 sinh vien() <<boundary» May chu ung dung +Logout() So 6 trinh tu (Sequence diagram) a ,laser • Ni t darn xi tat Xn M Anna xnet • segennetenann Laseaersel _Luay_chuogihno 1 : Logout() LJ 2 : Logout() Database 3 : %on du betir ILJI 4 : Xoa rre siM vien() 5 : Logot() 6 : Logout() So (16 16p chi tiet (Class diagram) 0 x User 35Hinh inh minh hip I 11:26 iliththitits Thong tin sinh vien a14982 A14982 THANG LONG UNiVERSiTY 1-- Lich thi chi tik Giai tich 2 Ca An toan mang HO thang thong tin quan lk cc. 14 Lap trinh ,Net Ca 1 4 ",$), ; '0' ' 44 ..) ) 0,2C Phu's:mg phap hiing biOn va cat tha thult tranh biOn , Dan nhap . iris C .1 , . L'. th ' t ar-f; 36UC #3 CAI DAT THOI GIAN CAP NHAT D6 phirc tap: Medium MO ta Chirc !tang cho phep ngtren dung thay dal khoang thai gian giira hai lin cap that hoac chuyen sang ched6 cap nhat thu ding. Tic nhan Chink Ngueri dung. Phu Khong co. Tien dieu kien irng dung kheri chay kh6ng co 18i, dang co tai khoan Tang nhap irrig dung. Wu dieu kien Thanh cling Thai gian glib hai Ian cap nhat dugc thay doi, nett che da cap nhat thu cling dtrgc thiet lap, irng dung se chi cap nhat khi nao 'wired dung sir dung chirc nang cap nhat lich thi. L8i Ong dung khong co thay dal. DAC TA CHUC NANG Luang sir kien chinh / kich ban chinh Chirc nang bit dau khi ngtreri dUng chon chat 'tang "Cai tat": 1.Giao di'en cai da, t hi'en thi len cho ngueri dung biet Ito dang de thai gian cap nhat la bao nhieu; 2.Thai gian cop nhat co the thay deli &Ira cac mac: •5 phin; •10 phut; •15 phtit; •30 phut; •Hang gier; •Thu ding. 3.Khi ngueri dfing chon mot mac thiri gian, Ung dung se Itru lai va to dOng cap nhat lich thi theo mac filed gian da dtrgc chon; 4.Neu ngueri dung chon "Thu ding", lich thi se chi dtrgc cop nhat khi ngueri dung chon chirc nang "Cop nhat lich thi". 37Scr dii hanh tong (Activity diagram) • I (Chan nut cal daft) W (Thiet lap khoang thoi gian giva 2 Ian cap nhat 1 (Luu thiet lap) 1 ( Cap nhat CO thi ) Luang sv kin phat sinh / kjch ban phat sinh Khang c6. Cac yeu cau d4c bit khac Khong c6. Tinh trang truoc khi thvc hi8n use-case (frig dung khari chay khong c6 161, dang c6 tai khoan clang nhap &rig dung. Tinh trang sau khi thvc hi8n use-case 1.Sau khi use-case dugc thvc hi8n thinh cong, thiet lap dm ngueri dung dirge Ung Mpg hru lai. 2.Neu use-case that bai thi 'rang thai img dung truck d6 kh8ng thay dai. 38Ditm ma rOng Kh6ng 66 Thit ke UML Sa difi lop phan tich (Analysis class diagram) a X ( <,-- --,,, /- ; i , I ) N User __Y Mao dien cal dat y SessionManager Local Service Sa dii trinkta (Sequence diagram) a A User HED r"-<- K__) : Gan Men cal Ant : SecsinnManager I : oral 1 : Chon nut cal dat() SenAre Pli 2 : Thiet lap 1hoi g n giva 2 Ian cap nhat() 3 : Luu thoi gian cap nhati4 4 : Luu thoi gian cap nhat() 3911:28 lichthitluS Sa do lap chi tier (Class diagram) a User «boundary» Giao dien cai dat «control» «control» SessionManager Local Service +Luu thoi gian cap nhat() +Cap nhat lich thi() Hinh anh minh hqa Thai gian cap nhat 0 10sec O 5 phtit 30 phiit 1 tieng O Thti ding Thai gian hen gia 1 ngay 3 ngay 7 ngay 40UC #4 CAI DAT THOI GIAN NHAC NHO DO phut tap: Medium M6 ta Chirc Wang cho pile') ngueri dung thay dOi khoing filth gian bao tru6c thai diem then ra cac mon thi trong Lich thi. Tac nhan Chinh Ngueri dung. Phu Khong co. Tien dieu kien Ung dung khai chay khong c6 16i. dang c6 tai khoan clang nhap ung dung. , HO drat kien Thanh citing Thai gian bao tnrerc ngay bit Tau mot mon thi ducc thay dai. ai Ung dung khong co thay dai. DAC TA CHUC NANG Lu6ng sir kien chinh / kich ban chinh Chac nang bit dau khi ngueri dUng chon chirc 'tang "Cal at": 1.Giao dien cai at hien thi len cho ngueri dung bier ha dang a thai gian nhic nha la bao nhieu; 2.Thai gian nhic nher co the thay dal giaa cac mac: •1 ngay; •3 ngay; •7 ngay; •10 ngay; •Khong bao. 3.Khi ngtrai dung chon mot mac then gian, ung dung se" km 141 vA to ctOng nhic nhet theo mac thai gian da ducc chart; 4.Neu ngtrai dung chon "KhOng bao", (mg dung se khong nhac A& cho ngireri dung biet khi co mon sap den ngay thi. 41So do hanh dang (Activity diagram) 0 1 Khong ( Chon nut cal dat) doi thoi Thay gian nhac nho Co Luu thiet lap 0 Luang sir kien phat sinh / kich ban phat sinh Khong c6. Cac ye'u au dac biet khic Khong c6. Tinh tang tnrac khi thyc hien use-case Ung dung phai clugc kheri dOng thanh ding vi dang dirge clang nhap bed ngueri ding. Tinh tang sau khi thuc hien use-case 1.Neu use-case thut hien thanh c6ng, thiet lap va thin gian nhac nil& se duce Itru vao ling dung. 2.Use-case khong thtrc hien thanh c6ng, hien trang img dung kb:Mg thay dOi. Dian] ma rOng KhOng co. 42Thiat kE UML So di lop phan tich (Analysis class diagram) _____,> 7------- ,K- ) ( -----, ) I User --> N), ,// N___} ---). K .) Giao dien cal dat SessionManager AlarmManager So do trinh ttr (Sequence diagram) 0 lJser : Gan 0 Men cal dat Secsinnilananct : : AlarmMananer : Chon nut cal dat 2 : Thiel is t i gian nhac nho() 3 : Luu thoi On nhac nho() 4: Luu thoi gian nhac nho() IL So do lop chi tiet (Class diagram) 0 ------> X User G<Ia<oboduien pi dat > «control» SessionManager <<control>> AlarmManager +Alannilanager.seto -.., +Luu thoi gian nhac nho() 43Hinh anh minh hna Then gian hgn gib duce chon trong cal at 1.1drthitlik5 5 phtit c__,} 30 phist 1 tieng U Thu tong Thai gian hen gid 1 ngay U 3 ngay 0 7 ngay 0 10 ngay 0 Kheing bac) 44UC #5 CAI DAT THOI GIAN LAP LAI THONG BAO DO phac tap: Medium Ma to Chac Wang cho phep nguai dUng thay den khoang thai gian lip lai girth min Ian thong No bao threw thai diEm din ra cac mon thi trong Lich thi. Tic nit Chinh Nguefi dung. Phu Khong co. Tien dieu kien Ong dung Uteri chay khOng co 161. clang co tai khoan ding nhap ling dung. ., Hatt dieu kien Thanh tong Thai gian bao trove ngay bit dau nit mon thi ducc thay dal. Lot Ong dung khang co thay cl6i. DAC TA CHOC NANG Luang su kien chinh / kith ban chinh Chirc nang bit diu khi nguai dung chon chirc Wing "Cai tat": 1.Giao dien cai dit hien thi len cho nguai dUng biet Ito dang de thin gian lip lai thong bao la bao nhieu; 2.Thai gian lip 141 thong bao co thE thay din giiia cac mac: •I phut; •10 phut; •30 phi; •60 phtit; •Khang lip I4i. 3.Khi nguai dung chon mot mac uteri gian, img dung se luu lai va to dOng lip 14i thong bao theo mac filth gian di ductc chon; 4.Neu nguai dung chon "KhOng lip lai", Ung dung se khang thuc hien viec lip lai th6ng bao va thong bao do chi dugc xuAt hien 1 lin duy filth cho nguai clang biet khi co mon sip dEn ngay thi. 45So di hanh dOng (Activity diagram) • 1 thong ( Chon nut cai dat) thoi Thay doi gian nhac lai Co ( Luu thiet lap 0 Luring str kien phit sinh / kich bin phat sinh Khong do. Cic yeu au dic biet }chic Khang co. Tinh trang tnrcerc khi thgc hien use-case fing dung phai dugc kheri dOng thanh cong va dang dugc clang nhip bed ngubi dung. Tinh trang sau khi thgc hien use-case 1.1n1411 use-case thgc hien thanh cong, thiet lip x4 then gian lip lai thong bio se dugc luu vao ang dung. 2.Use-case khong thtrc hien thanh ding, hien trang img dung Icheng thay dai. DiEm ma rung Khang ca. 46Thi'h't Ice UML So 6 16p phin tich (Analysis class diagram) ! 7------. User Giao then cal dat SessionManager AlarmManager So 6 trinh hr (Sequence diagram) a r--- , A r-A___.) i (7-4-.\, : User : Gan dien rai dat Cncsinnbtananer : alialareianaga 1 : Chon nut cai dat o() 2 : Thiet lap i n bp lai thong bao() 3 : Lbu thoi gian nhac lai thonc‘bap() 4 : Luu thoi gian nhac lai thoni So 6 16p chi tiet (Class diagram) 0 -------> X User Giao then earYtd>at «control» SessionManager > +Luu thoi Om nhac lai thong bao() NI «control» AbrmManager +AlarmManager.seRepeating() 474:06 fichthitlu Hinh anh mink hoa Thai gian hcn gib dtrqc chgn trong cai dat 3 ngay j 7 ngay J 10 ngay n Kh6ng boo Thai gian bao 10i 1 ph0t 0 10 phth 30 philt 0 1 giel 0 KhOng bac) Iai 48UC #6 NHAC LICH THI DO phirc tap: Medium MO to Chirc ning hien thi thong bao nhic nhe ve lich thi cho ngueri dung Tic nhan Chinh He thong. Phu Killing co. Tien dieu kien Ung dung kited chay khOng co I6i. Bang co tai khoan clang nh5p Crng dung. .‘ F1511 dieu ki 'en Thanh cong Hien thi th6ng bao. Lai Ung dung khong co thay dei. DAC TA CHUG NANG Luting sir kin chinh / kich bin chinh Chirc nang bit dAu khi ngueri dung di thief 15p day dil cac cai dal: I. DEn thai gian ngueri dung dA cai d5t, he tilting dua ra thong bao nhic niter ve lich thi ctia nguai clang. 2.NEu ngueri dung cai d5t the de ill& Iai thong bao. He thong se to dOng nhic lai thong bao do theo thai gian dinh truck. 3.Khi ngued clang chon vao thong bao d6, met thong bao khac dugc hien thi. Thong bao nay cho phep ngueri dung chon co tiep tuc 15p lai thong bao ve mon thi do khong. - Khi ngueri cliing chon tiep Mc 15p lai, thong bao ve mon thi se tiep tpc dugc bao lai theo thEri gian di dinh tnrec. - Khi ngued dung chon khong bao Iai, thong bao d6 se khong dugc 15p lai am. 49Sa 6 hanh (long (Activity diagram) • i ( Hien thi thong bao )4C Lap lai thong 0 Co lap lai bao !Chong lap lai Luting sv kien ph& sinh / kich ban phat sinh !Chong ca. Cac you eau d.c biet kit !Chong co. Tinh trang truck khi thin hien use-case ling dung phai duck kheri dOng thanh ding va dang duck clang nhap bed ngueri dung. Tinh trang sau khi thvc hien use-case 1.Neu use-case thuc hien thanh cong, thong bio se dugc hien thi. 2.Use-case khong thic hien thanh ding, hien trang ling dung khong thay dOi. Diem ma Ong Killing ca. 50Thiet k'E UML So d6 lop phan tich (Analysis class diagram) i zN)( K__2 \,. 2 K__}< A AlarmManager Receiver Mao then User Scr da trinh ttr (Sequence diagram) O0 AlarmManager : Receiver : GM Men 0 4 : Den thoi gian thong bao() : llser 11 2 • poi thong bao() 3 : Hien thi thong bao() 0 4 : Xem thong bao() 5 : Hien thi chon nhac 'al() 046 : Chon tran g thai() Scr d6 lop chi flit (Class diagram) «control» AlarmManager «control>, Receiver %_____), «boundary» Gan then +Notticationrianager.notty() +Notificatbn.settatestEyenInfoo User 51January 17, 2014 Mdroid Thong bao Iva chon nhAc lai 11 4:35 Thong bao Huy bao lai: Hinh anh mink hoa Thong bin khi sip den ngay thi Sp er,rn ngay thr, -!: - IchthitluS Ban sap thi mein: Gr. Dr • DucTign: nj 52UC #7 CAP NHAT LICH THI DO phirc tap: Medium MO to Chirc nang cho pile') ngueri dung cap nhat lich thi meri nhAt khi the do cap nhat thil cong duce cai Tat. O the dO cap nhat to don& chtic nang nay se dugc goi to dOng ma khong can tic Ong ciia netreri dung. Tac nhan Chinh Ngueri dung. Phu !Chong co. Tien dieu kien ling dung kheri chay Wring co 16i, dang c6 tai khoan (tang nhap ung dung, co ket not Internet. Hall dieu kien Thanh ding Neu c6 thay deli, lich thi se dugc cap nhat. Lai ling dung kitting co thay deli. DAC TA CHliC NANG LuOng su kien chinh / kich ban chinh I. Chirc nang dugc bit diu khi ngueri thing clang nhap vao &rig dung. 2.Neu ngueri dung thiet lap the do cap nhat thit cling. ling dung cho pile') ngueri dung co the cap nhat lich thi mei nhat khi sir dung chirc nang "Cop nhat lich thi". 3.Neu ngueri diing thiet lap the do cop nhat to dOng. ling citing se to dOng cap nhat lich thi meri nhat theo then gian da cai dit. 53Su dti hanh deng (Activity diagram) !Chong co 0 I ( Gr:iydchu heu duichlenv vu Co let not khong? Khong co intemet interne Thong bao cho dung i nguoi Co intemet Nhan thong tin to nay chu GCM du lieu moi Co du feu rroi Co du feu rtni 'thong' Luu du feu not vao co so du Reu 0 Luang sir kien phat sinh / Icich ban phat sinh Khong có. Cac yeu eau d4c biet khk Khong co. Tinh trong tnrat khi thIrc hien use-case Ngtreri dimg phai dang nhap vao img dung thanh cong. 54Tinh trang sau khi thirc hien use-case 1.Saukhi Mac hien Use thanh ding. lich thi mai nhAt se duat hien thi len !man hinh. 2.Neu Use — case thAt bai thi trang thai ling dung tnrerc do khong bi thay dei. Diem mar Ong Kh6ng co Thiet ke UML So 6 lerp phan tich (Analysis class diagram) Server Utilities User Giao dkn cap nhat lich thi Xu ly cap nhat Database Service GIN Service 55Sa do trinh to (Sequence diagram) - - _Luser Ciao dim ran nhat kit tit Xii ty ran nhat • ca-ta Weep a -Lien& 1 : Chon chuc nano cap nhat tch thi() 2 : Cap nhat hch thi() 3 : Cap nhat kh thi() 4:Gui eucaucapnhatkh hi() cr 6 : Luu kh thi() Sa ao 16p chi titt (Class diagram) Statue 5 thk) «control>, Xu ly cap nhat «control» Server «boudary» Semite «boundary» Pao then cap nhat kh thi +Cap shat idi IN( ¨Cap Mat Ich thi( Gild. h() ¨Cap that kb th() Database «control» Gal Peruke ¨Khan Eh Chia +Cap Mat kb thi() +Lou kb IN) 56Th6ng bao c6 cap nhAt mai Danh sach cac mon thi I 11:27 . lichthitlid . . Th8ng tin sinh vien a14982 A14982 January 17. 2014 Android 11:26 .. Clear i lichthitlu5 Co Ici [I mar' ' 4 Lich thi chi net Giai tich 2 Ca 1 An toan in4ng Ca: ' -A El§ th6ng thong tin quan 19 Ca: 1-4 \;,a-.c 2: 1:,-C, : u C , GO 010 Lip trinh ,Net Ca: 1-4Ng3, 2213.-0. 2-4' ri,. TO CIG Prurcrng phap Wing bin ye cac 06 thuit tranh Win Ca: 1-4 NE,, 2013.06-22. 03.00'00 4.3. ling dyng may chi' 4.3.1. Mo to Day la irng dung phia may chn (server) c6 nhiOm vu nap nhan thong tin to ang dung (client) nhim tInrc hiOn cac chirc Wang Itru gift thong tin va lc& not vai he thong thong tin dm tnrang Dai hoc Thang Long de lAy du liOu vO lich thi. 57CDang nhapD 0 x Thiet bi CDang xuat 4.3.2. So' do tong quan cdc chthr ming ciia nuiy chii 4.3.3. Cdc Mc nh4n tham gia He thong boat Ong to ding ma Miffing can co su tham gia dm con ngutri. 4.3.4. Cdc char ming chink cua he firing Dang nhOp: chirc 'fang nay tier, nhOn va xfr 19 thong tin clang nhOp cua ngueri dung dugc yeu eau tir phia img dung. Dang xuat: chile !fang nay tiep nhan va xir ly th8ng tin clang xuat cua ngueri dUng dugc you eau tir phia irng dung. Cop nhOt lich thi: chirc nang nay tiep nhan va xir 19 thong tin tir chat nang cap that Lich thi dugc yeu cau tir phia ling dung. 4.3.5. Mic td ale char nang cua ring dyng UC #1 DANG NHAP DO pluic tap: Medium MO to Chtic nang tiep nhOn thong tin va xu: 19 thong tin clang nhOp cua ngueri dung dugc yeu cau tir phia img dung. Tac nhan Chinh Kleing col Phu KhOng co. Tien dieu kien He thong khong co 16i. ., HOu thou kien Thinh ding Th8ng tin dugc you cau tir phia img dung va xfr 19. Thong tin ve ngtreri dung dirge luu frit tai may chi,. Lai 1-1. th6ng khong thay d6i. 58DAC TA CHUG NANG Lung sir kiOn chinh / kjch ban chinh CI-16.c Wang nay hoat dgng khi c6 yeu du tir phia img dung: 1.HO thgng tiOp nhan thong tin dugc gtii dOn to img dung; 2.HO thgng kiOm tra thong tin trong co ser du liOu dO tranh tang lap do' liOu: 3.Th6ng tin vO ngutri dimg dtrgc Itru trong co se du liOu oh may chti. So 6 hanh dOng (Activity diagram) e nIF Ciep nhan thong tin Da co Chua co Kern tra ton tai RegistrationID Cap nhat ( Them rroi ) O Luting su kien phat sinh / kjch ban phat sinh Khong cep Cac you can dAc bit khac Khong c6 Tinh tang tut khi thuc hiOn use-case Server dA dugc bast va hout dOng binh thoOrng Tinh trong sau khi thuc hiOn use-case Thong tin ye ngugi dung dugc km lai trong co s& du liOu Diem ma Ong Khong c6 59Thi6t ke UML So 6 lop phan tich (Analysis class diagram) < i laSDL ( , '. )1 ''`,.. -.-. 9 \--1 Tiep nhan thong tin Xu ly thong tin Xu ly CSDL So 6 trinh nr (Sequence diagram) «boundary» : Tien nhan thonn tjp «control» _LilliSill «control» : Xti ty rein; _Sat 1 : Nhan th g tin to cient() Kiemtra thong tin trong csdlii. 3 : Lay du Neu ye nguoi dungii, rirr Lay du feu ye nguoi du 0 i Erc: Du ieu nguoi dung() 0.11 6 : Du feu nguoi dung() 7 : Tao not nguoi dung() 1_1: 8 : Luu thong tin rroi() 9 : Cap nhat nguoi dung() iii 11: io : Luu thong tin rnokliti So dt 16p chi het (Class diagram) Xu ly thong tin Xu ly co so du leo Tiep nhan thong tin MIX +rem tra ton tai nguoi dung() +Tao not nguoi dung() +Cap Mat nguoi dung() +Lay thong tii nguoi dung() +Tao nd nguoi dung() +Cap Mat nguoi dug( +1000 --> 60UC #2 DANG XUAT DO phirc tap: Medium MO to Chirc nang tiOp nhan thong tin va xii 19 thong tin clang xuAt ctia nguoi dung duct yeu cau tir phia img dung. Tic nhan Chinh !Chong cc). Phu Khong co. Tien diet' kien He thong kitting c6 16i. , Hau dieu kien Thanh ding Thong tin dugc you call tir phia ling dung va xi: 19. Thong tin ve nguti dung dugc xir 19 va km tr6 tai may chit'. L6i HO thOng 'thong thay del. DAC TA CHU'C NANG LuOing su kien chinh / kich ban chinh Chat nang nay hoat Ong khi co yeu call tir phia fing dung: 1.HO th6ng tiep nhan thong tin dugc gUi den tir Cmg dung; 2.HO theing kiem tra thong tin trong co stir du lieu de tranh trong 14p du liOu; 3.Thong tin ve ngueri dung door thay deli trong co ser du lieu cila may chi), ma sinh vien se dugc xoa ttrong *rig veil RegistrationID duce km trong co sesdir liOu. So d6 hanh dO'ng (Activity diagram) • I Cep nhan thong tir) i Cap nhat trang thai nguoi dung Luting sty kien phat shill / kich ban phat sinh )(hong c6 61Cac you cau dac bit khac Khong c6 Tinh trang truerc khi tlurc hien use-case MA sinh vien twang (mg vai REGID duce luu tra cone veri ma phien ban lich thi Tinh tang sau khi tlurc hien use-case Th6ng tin ve REGID van duce km tr& nhung thong tin ye ma sinh vien va ma phien ban lich thi bi >tea bO Diem mer rang KhOng c6 Thief ke UML Sa de lop phan tich (Analysis class diagram) t• < esCIL I ) —> --> K } Tiep nhan thong tin Xu ly thong tin Sa d6 trinh to (Sequence diagram) «boundary» : Den nhan thnna tin «control» LALLbal3120911 «control» ' Xii lv CCM _l_CSQL 1 : Dang xuat() 2 : Dang xuat() 11-1 3 : Cap nhat IN thong tin nguoi dung() 111.1 Sa d6 lap chi tiet (Class diagram) Xu ly co so du lieu llep nhan thong tin >i Xu ly thong tin CSEIL +DPW) +139outo 04014 --> 62UC #3 CAP NHAT LICH THI DO phirc tap: Cao MO to Chirc nAng tiep nhan thong tin va xir 19 thong tin cap nhat lich thi cua ngu6i dung dugc yeu cau tir phia (mg dung. Tic nhan Chinh Khong c6. Phu Khong cep. Tien dieu kien He th6ng khOng c6 16i. ., Hau Vett kien Thanh cong Thong tin dugc you cau tir phia irng dung va xi: 19. Lich thi meri dugc gui tra ve cho irng dung. Loi He th6ng khong thay d6i. DAC TA CHUC NANG Lu6ng su kien chinh / kich ban chinh Chirc nAng nay hog dOng khi co yeu au tir phia irrig dung: 1.He th6ng tiep nhan thong tin dugc giri den tir img dung; 2.He th6ng kiem tra thong tin trong co ser du lieu; 3.He th6ng My du lieu tir he th6ng thong tin truerng D4i hoc Thang Long clua vao thong tin dugc cung cap tir Ung dung; 4.He thring kiem tra tinh meri dm du lieu dugc lay ve; 5.Giri tra chi lieu lich thi meri tai ting dung thong qua GCM; 6.Thong tin ve lich thi va ngtred dUng dirge Itru nit trong co s& dlr. lieu. 63So d6 hanh deing (Activity diagram) Chan yeu cau cap nhat lich thi 1 he thong mu) Cia,y Nth thi to Khong co Item tra du feu not Ida Co co la du Feu (Gui du Neu qua GCM (Gui du Neu ye ung dung) 0 Lung str kin phat sinh / kich ban phat sinh Khong co. Cac y.eu cau dac bi6t khac Khong co. Tinh trang truck khi thuc hi6n use-case He th6ng kheri doing thanh ding. Tinh trang sau khi thvc hi6n use-case . Lich thi mei &roc giri tei (mg dung thanh ding. DiEm mar rang KhOng co. 64tSDL 6 : Gil ich thi0 Thiat ka UML 7: Gui thi() Sa c16 16p phan tich (Analysis class diagram) Su ly Service Service i n l i_____2 He thong Dal hoc Thang Long GUI Service May dui ung dung Sa d6 trinh tn. (Sequence diagram) •XII N SPIV VP •W thong nai hoc Thane I nop _SSA. rtM SPIVirP Yeu cau cap nhat Ich thi() 2 : eY kh tti() Fs, 3 : Tra ve ich thi() 4: So ianh leo cla co() 5 : Lou th thi() 65Su d6 lop chi filet (Class diagram) CSDL «control» «boundary» /Cu ly Service «control» GCM Service «boundary» Service May dm ung dung +Lay kh thr() +Luu kh thi() +Gui Rh th() +Gui kh th() «boundary» He thong Dal hoc Thang Long +Tra ye kb thK) 4.4. Phan tich thiet ice du. lieu 4.4.1. Mo td plain tick di"r It& He th6ng nhic lich thi can CO co ser du lieu de dam bao dugc cac chirc nang sau: —Thong tin ve ngueri thing va thiet bi ( ma sinh vien va RegistrationlD) dugc Itru tril teen he th6ng; —Thong tin ve lich thi mei nhAt dugc Itru try tai thiet bi cita nguiri dung. Do do, can phai co hai co se dr lieu olO Itru tit thong tin: —Co se du lieu Itru tra thong tin nguari dung va thiet bi duge sir dung cho img dung may chit; —Cu sir MI lieu kru ter lich thi dirge sir dung cho irng dung Android. Cac thong tin can kru —U'ng dvng may chit: thong tin ve ngtred dimg +MA sinh vial; +MA thiet bi (RegistrationlD); +Phien ban lich thi. —ting dvng Android: Lich thi ctia sinh vien +MA mon thi; +Ten mon thi; +NO), thi; 66+Ca thi; +Phong thi; +Tinh tang. 4.4.2. du frac bang Ung dung may chit: Bang ACCOUNT Colum name Description Datatype Length Allow null ID Ma dinh danh int No MASV Ma sinh den Varchar 6 No REGID Ma dinh danh text No VERSION Phien ban Lich thi text Yes PRIMARY KEY ID Ung dung Android: Bang LICHTHI Colum name Description Datatype Length Allow null ID Ma dinh danh int No MAMON Ma mon thi Varchar 6 No TENMON Ten mon thi varchar 50 No NGAYTHI NO), dien ra mon thi datetime No CATHI Ca thi Varchar 5 No PHONGTHI PhOng thi varchar 10 No TINHTRANG Tinh tang ctia mon thi varchar 5 No PRIMARY KEY ID 4.5. Ket qua xly dkrng thig dyng —Ung dung hoat dOng tot dung nhu yeti au da dat ra; —Giao dien thin thien, de ding sir dung; —Lich thi dugc cap nhat nhanh chong, chinh xac. He thong nhic nher hoat clOng chinh xac. 67CHLYONG 5. CAC Kt THU3T XU.Lt QUAN TRQNG Trong chtrcrng trugc, nhom tac gia dA xay dung huerng Oat trien cho he th6ng nhic lich thi cho sinh vien Thang Long. D6 mei la nhung buoy phac than, phan tich thiet Ice co ban trong qui trinh phat trien phan mem. Trong chuong nay se di sau vao the hien cac kSi that nhu xis 19 thOng diep dugc gui ve tir GCM, Itru tni dir lieu tren thiet bi Android, sir dung service tren Android... De tien theo doi, nit tic gia se trinh bay theo trinh to giri nhan du lieu theo ino hinh 3- I . 5.1. Dang ky thiet bi nfri GCM de nhan RegistrationlD Tnrerc het, to phai khai bao cung cap quyen cho cac thanh phin dugc phep chay tit img dung trong file AndroidManifest.xml. Nhang quyen nay la can thiet de Ung dung c6 the sir dung dugc GCM. <permission android:name="com.pushschedule.permission.C2D_MESSAGE" android:protectionLevel="signature"> </permission> <uses-permission android:name="com.pushschedule.permission.C2D_MESSAGE" I> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.VIBRATE"/> —INTERNET — Khai bao cho phep sin dung dich vu internet; —ACCESS NETWORK STATE — De truy cap trang thai mang ( dung de xic dinh trang thai hien thin cua mang; —GET ACCOUNTS — GCM can phai co tai khoan Google; —WAKE _LOCK — Dinh thirc thiet 1)1 khi Man dugc thong diep/tin nhan; —VIBRATE — Cho phep rung. Sau khi da khai bio xong, de cep the sir dung dugc dich vu GCM, thiet bit can phai c6 RegistrattionID. Dang k9 registration ID: 68GCMRegistrar.checkDevice(_context); GCMRegistrar. checkManifest(_context); regld = GCMRegistrar.getRegistrationId(_context,SenderID); GCMRegistrar la mgt lap trong thy vien GCM ctia google va dtrgc them vao qua khai bao: import com.google.android.gcm.GCMRegistrar; Khi ggi ham GCMRegistrargetRegistrationld(), thiet bi se dugc clang k9 vEri GCM vEri tham se Huy& vao SenderiD, gia tri tra ve se la mgt chugi dinh danh duy nhat thiet bi. 5.2. Girl thong tin yeu au den may chii ting dyng (application server) Trong img dung nay, de Ow vu cho vies giao tiep, girt yeu cAu tir thiet bi den may chit, nhom tac gia da xay dung mgt lap rieng biet de dam trach nhiem vu nay. De c6 the giao tiEp voi may chit, irng dung sir dung giao thirc HTTP de truyen da public static void postToServer(List<NameValuePair> nameValuePairs){ try{ // url where the data will be posted String postReceiverUrl = "http://t1u.hol.es/post_data_receiver.php"; Log.v(TAG, "postURL: " + postReceiverUr1); // HttpClient HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(postReceiverUrl); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // execute HTTP post request HttpResponse response = httpClient.execute(httpPost); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { String responseStr = EntityUtils.toString(resEntity).trim(); Log.v(TAG, "Response: " + responseStr); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (I0Exception e) { e.printStackTrace(); } 69Ham postToServer nay c6 nhiem vu nhan TO' so truyen vao IA danh such cac tham s6 can thiEt va giri chUng den Server dE khi nhan dugc goi tin HTTP. Server se cei du din lieu d'E xir 19. DE thire thi viec gui, (mg dim sir clung cac thu vien sun có cua java nhu HttpEntity, HttpResponse, HttpClient... thong qua lenh khai bao import: import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; 5.3. Server nh4n thong tin va ycir lit (lit lieu Trong Ung dung nay, tac gia sir dung phuang thirc POST cila giao thirc HTTP de gui eta lieu dEn Server. Do do, phia server se nhan dirge der lieu thong qua mang S_POST (Server dirge xay dung Wang PHP). Dga vac, cac du lieu dirge china trong mang $_POST ma Server se tiEn hanh phan tich va sir IS, du lieu. Quy trinh dirge me to khai gnat nhu sou: —Tien hanh phan tach the thanh phan cua mang S_POST de co dirge RegistrationID va hanh dOng thgc hien (dang nhAp, dang xuAt hay 4p nhat lich thi). —Xi: 19 hanh dOng: +Neu IA dang nhap thi Server se tiEn hanh liru gia tr1 ma sinh vien dirge giri len cung veri Registrationld tucmg img; +NEu IA dang xuAt thi Server se tiEn x6a ma sinh vien voi Registrationld tucmg ling; +Neu IA cap nhat lich thi, Server se tien hanh viec cap nhat lich thi thong qua Webservice cua nhA truang de c6 the lay dirge lich thi chinh xic nhAt. Sir dung SOAP trong PHP dE kEt not dEn Webservice va truy van du lieu Gieri thieu qua so ve SOAP, SOAP la gi? SOAP IA viEt tit elm Simple Object Access Protocol, la mot giao thine giao tiEp co eau true nhu XML va ma h6a thanh dinh clang chung cho cac img dung trao d6i vol nhau. SOAP IA melt dAc to viec sir dung cac Lai lieu XML then dang cac thong diep. Ban than SOAP khong dinh ra cac nger nghia irng dung hoac each cii dal chi tier. SOAP cung cap mot co chE don gian Ira gon nhe cho viec trao doi thong tin co cAu true va dinh dang gala cac thanh phan trong mot moi trubng phan tan sir dung XML. SOAP dirge thiEt ke dga ten nhang chuan nhim giam chi phi tich hgp cac he thOng pit tan xay dung ten 70nhieu nen tang khac nhau a mat cang thap cang Mt. Die to ve SOAP dinh nghia mot mo hinh trao d6i at: lieu dip tren 3 khai niem co ban: Cac thong diep la cac tai lieu XML, chUng clugc truyen di tir ben giri den bEn nhin, ben nhin c6 the chuyen tiep dit lieu den not khac. Khai niem co ban nhat cua mo hinh SOAP la viec sir dung cac tai lieu XML nhu flitting th6ng diep trao del. Dieu nay co nhieu tru diem hon cac giao thirc truyen cla lieu khac. Cac thong diep XML co the dugc tong hop va doc veri met 1)0 soan Mao text don gian, to co the lam viec vol XML tren hau het moi nen tang. Lay der lieu tir Webservice thong qua SOAP: $client = new SoapClient(Sur1); $lichthi = $client->GetlichThi(array("MaSinhVien"=>$studycode, "user"=>"test", "pass".>"testl@R") )->GetLichThiResult->ClichThi; Ham SoapClient(Surl) se kheri tao nen mot d6i tucrng SOAP client ket not den Webservice thong qua &rang din Surl.Trong tnremg hop nay, Surl = http://dkonline.thanglong.edu.vn/formobile.asmx?WSDL Slichthi la mot ming cac gia tri dugc Sclient lay ve thong qua ham GetLichThi(). Ham nay duoc phia Webservice cung cap de cho phep cac may tram (client) fly cap va lAy du lieu. Da lieu duce tra ve Er clang mang JSON. Xir IY dir lieu sau khi lay dugc tir Webservice caa nha tnrerng Mr' lieu dugc tra ve ix clang ming, do d6 sir dung yang 14 de co thE b6c tach toan b6 chi lieu thu dugc va dinh clang lai du lieu chitin bi cho qua trinh giri di': lieu cho GCM. foreach ($lichthi as $monthi) { $ngaythi = explode("T", $monthi->NgayThi); $ngaythi = $ngaythi[0]; $date = new DateTime($ngaythi); $ngaythi = $date->format("Y-m-d"); if( $startDay > strtotime($ngaythi)) break; $ct = explode("/",$monthi->CaThiMaPhongThi); $pt = $ct[0]; $ct = $ct[1]; $subject = array("MASV"=>($monthi->MaSinhVien), "TENSV"=>($monthi->MaSinhVien), "MAMON"=>($monthi->MaHocPhan), "TENMON"=>($monthi->TenHocPhan), "NGAYTHI"=“str_replace("T"," ",$monthi->NgayThi)), "CATHI"=>($ct), "PHONGTHI"=>($pt), "TINHTRANG"=>($monthi->TinhTrang), 71"VERSION"=>null); array_push($listSubject, $subject); } SlistSubject se chira wan bo du lieu lich thi da dugc to chirc va dinh clang lai (16' cho phir hqp. Sau khi da to chirc 14i da Ivo tao ngu6n dau vao cho viec gth thong diep, SlistSubject se &roc ma hoa de hm va0 cu so du lieu nham xac dinh phial ban sau nay. Viec ma hoa se dam bao voi mcii ban thong diep khic nhau deu dugc xac dinh duy nhAt. 5.4. Gni thong diet) den GCM De giri dugc thong diep den GCM. to tiep tgc sir dung giao that HTTP cl& truyen pal tin. cURL la mot thu vien trong PHP cho phep tao ra cac yeu eau HTTP. public function send_notification($registatoin_ids, $message) { // include config //include_once './config.php'; $doc = simplexml_load_file("server_config.xml") or die("Error: Cannot create object"); // Set POST variables $url = 'https://android.googleapis.com/gcm/send'; $fields = array( 'registration_ids' => $registatoin_ids, 'data' => $message, ) ; $headers = array( 'Authorization: key=' . "AIzaSyBW5H0mAxNubGGVDbF74s5-mhoODOnTo9A", 'Content-Type: application/json' ); Mheaders = array( 'Authorization: key=' . $GOOGLE_API_KEY, 'Content-Type: application/json' );*/ // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Disabling SSL Certificate support temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 72curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // Execute post $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } // Close connection curl_close($ch); // echo json_encode($fields); / Ham send_notification() se dam nhiem viec girt du lieu den GCM. Trong to chirc gal tin giri den GCM can cac co cac thong tin nhu RegistrationId de xic dinh thiet bi nhan, API key de xac thgc dich vu va thong diep girl can gin. 5.5. X& Iy thong diet) dugc gin den tir GCM tan thiet bi Android Day la bu6c cugi ding trong most qua trinh girl nhan thong tin qua GCM. Cong nghe Push Notification sir dung GCM nhu mat nai luu trU cac thong diep dugc you au gin den thiet bi. Trong thuc te, khong phai Itic nao thiet bi cling dugc ket not Internet sail sang, do do GCM se clang vai tr.?) la nai luu tru thong tin, ngay khi thiet 13t co ket not intemet, GCM se lap tdc "day" cac thong diep xuOng cac thiet bi dga vao RegistrationId. De img dyng nhan dugc thong diep, can xay dung mgt lap dam nhiem chirc nang nay va dugc Ice alga tir lap GCMBaselntentService trong thu vien GCM ciia Android. Phucmg that onMessage() dugc qua tai lai trong 16p ke thira c6 chirc nang nhan thong diep dugc gin den qua GCM. @Override protected void onMessage(Context context, Intent intent) { Log.i(TAG, "Received message"); Bundle data = intent.getExtras(); String message = data.getString("lichthi"); DatabaseHandler db = new DatabaseHandler(this); generateNotification(context, "Co lich thi mdi!"); Log.i("Chuoi nhan ve:",message); try { lichthi = new )SONArray(message); db.saveToDatabase(lichthi); getList(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } getVersion(lichthi); 73getStudylnfo(lichthi); displayMessage(context, "new"); Khi nhan throe du lieu girl ve thong qua cau lenh intent.getExtras(). Da lieu se duce luu vao co so air lieu tren thiet bi. Do dirge luu tra lai nen sinh vien co the truy van lich thi bat k9 lac nao ma khong can den mang Internet. public void saveToDatabase(JSONArray _lichthi){ Log.i("DatabaseHandler","Deleting older record"); deleteAllRecord(); Log.d("DatabaseHandler: ", "Inserting .."); try{ for(int i = 0; ic_lichthi.length();i++){ JSONObject monthi = _lichthi.getJSONObject(i); MonThi mt = new MonThi(monthi.getString("MAMON"), monthi.getString("TENMON"), monthi.getString("NGAYTHI"), monthi.getString("CATHI"), monthi.getString("PHONGTHI"), monthi.getString("TINHTRANG")); addMonThi(mt); }catch (JSONException e) // TODO Auto-generated catch block e.printStackTrace(); } Lich thi duce truyen vao dual dung mang JSON, sau d6 duce bee tach va to chat lai va truy'en vao ham addMonThi() de Itru vac, cu so di' lieu. Trong Android sir dung co so der lieu SQLite. public void addMonThi(MonThi mon){ SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_MAMON, mon.getMaMon()); values.put(KEY_TENMON, mon.getTenMon()); values.put(KEY_NGAYTHI,mon.getNgayThi()); values.put(KEY_CATHI, mon.getCaThi()); values.put(KEY_PHONG, mon.getPhongThi()); values.put(KEY_TT, mon.getTinhTrang()); Log.i("Insert mon thi",mon.getTenMon() + " ; " + mon.getNgayThi()); db.insert(TABLE_SCHEDULE, null, values); db.close(); 5.6. Service trong Android Cong nghe Push Notification cho phep nhang thong diep mai duce cap rthat gin nhu ngay tiro thi va dam bao tinh uteri gian thuc, c6 skr thay dai se c6 thong bio ngay tire thi. Nhung de c6 duce skr "tirc thi" 46 van can phai c6 mot ngu6n yeu au thong tin. 74Timing thuiringde thong tin ducfc cap !that tiled an he thane se phai lien tuc kiErntraithih mai cua thong tin. Do vay he th6ng can lien we kiEtri tra, girl yeti cAu.kloangthed gian gni yeu cAu kierntra giaa hai Ian gui cing nhO thi tinh cap nhatnadd cita du lieu cang Mt. De giai quyetvandenay,chnngtoi R.:dung Service, naatthanhphancualmgdung Android. Trong cac phantrtporc da trinh bay, ve ly thuyetco ban ctia Service trong Andoird. Trongphannay,chUngtoisetaptrunevaok9thuatimgdungServicevaogiaiquyetbaitoan. Mydunglop LocalService LOpLocalServicedtpc ke thirata lop Servicecc:is:andmAndroid. N40t Service dugc khdi tao bang ham onCreateudugc bat dau bingonStart0 hoac onStartCommand0.0daychungtoisirdunghamonStanCommandOdecothesirdunggia tri tra ve START STICKY, giup service khong bi ngimg khi ung dung bi "killed". public int onStartCommand(Intent intent, int flags, int startld) { Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); Log.d("Service", "onStart"); if(session.getTimeRequest() < 0) stopMyThread(); else startMyThread(); return START_STICKY; } Service se tgo ra mot fien trinh chay ngArn ma khong anh htrang vao tien trinh chinhAlodinagtientrintichinhbidinagthiservicevIncOthEtieptuc. Tan dung tru diem nay, chung tai dung service de co nnOtthLt trinh gai yeu cau lien fix ve phiatnnaychit.thrttrinhnayse khong bi gian doan hay anh htniTT khi Mag tingdungdovaydarnbioquatrinhgniyeucAudienradeudanva hen*. DEWmduce chu trinh lien tuc chung tell sir dung luting (thread)d6 có the lam tre qua trinh lap. public void startMyThread(){ timeRequest = session.getTimeRequest(); if(timeRequest > 0){ Log.i("Time Request:",String.value0f(timeRequest)); if(stopThread) stopThread = false; if(myThread == null && Isession.getThreadState()){ myThread = new Thread(){ @Override public void run(){ while(true && timeRequest > 0) { try { if (cd.isConnectingToInternet()){ Log.i("Server","Thread is running"); // getSchedule(); 75final HashMap<String, String> user = session.getUserDetails(); // ServerUtilities.getScheduleExam(getApplicationContext(), user.get(SessionManager.KEY_REGID),user.get(SessionManager.KEY_VERSION)); Thread.sleep(1000*timeRequest); } catch (InterruptedException e) // TODO Auto-generated catch block e.printStackTrace(); if(Isession.getThreadState()){ myThread = null; Log.i("Server","Stoped Thread"); break; } } } }; myThread.start(); session.setThreadIsRunning(); Log.i("Thread State",String.value0f(session.getThreadState())); else return; Lu6ng myThread duce tao ra lap lai vari d6 tre tay chon cua ngueri dung. Thread.sleep(1000*timeRequest); VA chi thing lai khi c6 diau kin tac dOng if(!session.getThreadState()){ myThread = null; Log.i("Server","Stoped Thread"); break; 76Ket not va dieu khien Service Tao ket not den Service: private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { mBoundService ((localService.LocalBinder)service).getService(); } public void onServiceDisconnected(ComponentName className){ mBoundService = null; } }; Kheri dOng Service: MainActivity.this.startService(startServiceIntent); 5.7. Cli Cat Inn gia thong bio De phuc vu cho viec thong bao lick thi den ngueri dimg, nth:il tic gia sir dung lap AlarmManager. AlarmManager c6 quyen truy cap vao cac dich vu he thong bao dOng. Veri su gitip da dm AlarmManager ban co the len lich thuc thi mot doan code nao do trong tuang lai. DOi tugng AlarmManager khong the kthai tao tRrc tiep tuy nhien no co the dugc thy bang each g9i Context.getSystemService (Context.ALARM_SERVICE). AlarmManager mgr = (AlarmManager)MainActivity.this.getSystemService(Context.ALARM_SERVICE); AlarmManager Ilion clang k9 yeti Intent. Khi den theri gian bao Ong, cac Intent da dugc (tang ky veri AlarmManager, dugc phat song bed he tilting to dOng. Intent nay se khai Ong img dung net' img dung do khong chay. Gng dung dugc khuyen de sir dung AlarmManager khi ban muOn code cim phan mem chay dugc trong I thai gian rieng biet, tham chi ca khi phan mem d6 hien dang khong hoat dOng. Pendinglntent pi = PendingIntent.getBroadcast(MainActivity.this,notificationCount, PendingIntent.FLAG_UPDATE_CURRENT); mgr. set(AlarmManager.RTC WAKEUP,when, pi); day, "when" chinh la khoang thai gian cher cho den khi AlarmManager duct pi, kern vei da th I PendingIntent khai tao I Broadcast kem then Intent china di: lieu can giri. Intent i = new Intent(MainActivity.this, Receiver.class); i.putExtra("tenMon", tenMon); i.putExtra("NotifyCount", notificationCount); Gig du lieu bao ten mon thi va notificationCount. NotificationCount lam nhiem vu dem cac mon thi co the duce th6ng bio. Khi ngtreri dung co nhieu hcm I mon sap den ngay thi. WI mon se tucmg img veri I thong bao rieng biet. 77De nguei sir dung nhan biet thong bao dtrot hien thi tren thiet bi, tac gia sir dung 16p NotificationManager trong Broadcast. Th6ng bao co the co cac hinh thirc khac nhau: —Met Neu tuqng ma di trong thanh tong thai va co the truy cop thong qua cac thao tac ( khi ngtrai clung chon no , met Intent dugc chi dinh co the duqc goi ra ); —Bat hoac nhAp nhay den LED tren thiet bi; —Canh bao tiara sir dune bang cach nhAp rthay den nen , choi met am thanh, hoac rung. NO duqc khai bao nhu sau: NotificationManager mNotification = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); String tenMon = intent.getStringExtra("tenMon"); String mess ="Sep den ngey thi!"; Notification notification = new Notification(R.drawable.ic_launcher, mess, System. currentTimeMillis()); notification.setLatestEventInfo(context, "Ban sap thi mon:", tenMon, contentIntent); mNotification.notify(intent.getIntExtra("NotifyCount",0), notification); Khi den thai gian da hen tnr6c, 1 thong bao ye mon thi sap din ra se dugc hien thi len thanh thong bao cua thiet bi gem: —tenMon: ten dm mon thi sap then ra; —mess: fieu de cna thong bao 5.8. Cli Ot thai gian nhic lai thong bin ling dung cho phep ngubi dung tuY choir thong bac, do5 co the duqc lap di lap lai theo 1 khoing thai gian dinh san hoac thong bao de chi dtrot hien thi 1 tan. Khi ngueri dung thiet lap thong bao dugc nhAc lai, Prang to nhu voi viec thOng bao dugc hien thi 1 Ian, ta se sir dung 16p AlarmManager: AlarmManager mgr = (AlarmManager) MainActivity.this.getSystemService(Context.ALARM_SERVICE); Pendinglntent pi = PendingIntent.getBroadcast(MainActivity.this, notificationCount, PendingIntent.FLAG_UPDATE_CURRENT); mgr.setRepeating(AlarmManager.RTC_WAKEUP, when, session.getTimeRepeat(), pi); O day de thiet lap thong bao dugc lap di lap lai theo I khoang tiled gian dinh s'an ta diing ham setRepeating (int type, long triggerAtMillis, long intervalMillis, Pendinglntent operation) voi cac thong se: Type: kieu thong bao dugc thiet lap; TriggerAtMillis: then gian thong bao bat dau hien thi (tinh theo mili giay); -IntervalMillis: khoang cach gitia moi Ian thong bao dirge lap lai; Operation: hanh dOng dirge gei khi thong bao xuAt hien. 78KET LUAN VA HONG PHAT TRIEN 1.Ket luOn COng nghe di d(ing hien nay dang Oat trien vgi Mc d6 nhanh, nhieu cong nghe inch dugc Ling dung, da, C biet la sg phat glen ctia dien thoai thong minh cling nhu nen tang di Ong dan clan cang ngay cang tr6 nen ph6 bien. Viec pith trien va ling dung cac cong nghe di d6ng vac) desi song hien nay dang la xu the Oat trien manh coa cong nghe thong tin not chung va cda nhimg nha ph& then phan mem not rieng. Do vay. de tai nay da cho chung toi co hai dugc tim toi, nghien ciru, Ung dung nhimg cong nghe di doting mei nhat. qua do trao d6i dugc kinh nghiem va ky nang trong viec Oat trien phan mem. phii hgp vai qua trinh hoc tap tai truang Dai hoc Thang Long. Viec thuc hien de tai nay cling la mat tai lieu de cung cap cho sinh vien nhcing khoa filo theo c6 the than khao, nghien ciru. phtic vu tot hon nita trong viec hoc tap tai tnrOng Dai hoc ThOng Long. 2.Htning pith trait Vol kha nang truyen da lieu nhanh va chinh xac, kip thal cua cong nghe Push Notification, ngoai Ung dung cap nhat lich thi cho sinh vien, cong nghe nay con ma ra nhieu huang phat trien ling dung tien ich cho sinh vien han nfra nhu: —Ttr dOng cop nhOt cac thong bao mai cam nha tnrang: nhimg th6ng bao mai nhat cua nha truing cep the dugc cap nhat nhanh nhAt. mai nhAt va kip thai nhAt, dac bie't la nhang th6ng bao khAn; —Ttr dong cap nhat cac thong bao &la cac giang giang vien cua timg lop co the dua ra cac thong bao, nhAc niter cho sinh vien dia lop mitt Viec nhAc nit& true ti6p dugc gin den chinh xac sinh vien cua lap se too hieu qua Mt hon viec chi dang thong bao ten website nha tnrerng, giap sinh vien nam bAt Mt han thong tin tir giang vien; —Phat trien (mg dung thong bao nhAc nit& den timg sinh vien, to de tang hieu qua caa viec nhAc nha nhu nhAc niter viec d6ng he phi, nOp cac giAy to can thiet. 79TAI LIEU THAM KHAO I. Patrick Niemeyer, Jonathan Knudsen, Learning Java 2"d Edition, O'Reilly, 2002. 2.Reto Meier, Professional Android 4 Application Development, John Wiley & Sons Inc, 2012. 3.Samisa Abeysinghe, RESTful PHP Web Service, Packt Publishing Ltd, 2008. 4.Tai lieu danh cho nha Oat tri4n Android ctia Google tai trang web: http:Ael elopenandroid.com 80
- Xem thêm -