Mobile Application Lab

Embed Size (px)

Citation preview

  • 7/23/2019 Mobile Application Lab

    1/53

    THIRUMALAI ENGINEERING COLLEGE

    KILAMBI, KANCHIPURAM-631551

    DEPARTMENT OF COMPUTER SCIENCE ANDENGINEERING

    Mobile Application Development Laboratory

    (CS6611)

    NAME :

    _________________________________

    REG. NUMBER : _________________________________

    SEMESTER :

  • 7/23/2019 Mobile Application Lab

    2/53

    1. Develop an application that uses GUI components, Font and Colours

    S.N

    OEXE!I"EN#S

    1 Develop an application that uses GUI components, Font an Colours

    ! Develop an application that uses Layout Mana"ers an event listeners#

    $ Develop a native calculator application#

    % &rite an application that ra's basic "raphical primitives on the screen#

    ( Develop an application that ma)es use o* atabase#

    6 Develop an application that ma)es use o* +SS Fee#

    Implement an application that implements Multi threain"

    - Develop a native application that uses G.S location in*ormation#

    / Implement an application that 'rites ata to the SD car#

    10 Implement an application that creates an alert upon receivin" a messa"e#

    11 &rite a mobile application that creates alarm cloc)

  • 7/23/2019 Mobile Application Lab

    3/53

    Simple application to chan$e %ont si&e and color o% te'tvie(

    12pen eclipse or anroi stuio an select ne' anroi pro3ect

    !Give pro3ect name an select ne4t$ Choose the anroi version#Choose the lo'est anroi version5Anroi !#! an select ne4t

    % nter the pac)a"e name#pac)a"e name must be t'o 'or seprate by comma an clic) *inish

    (Go to pac)a"e e4plorer in the le*t han sie#select our pro3ect#

    6Go to res *oler an select layout#Double clic) the main#4ml *ile7o' you can see the Graphics layout 'ino'#

    -Clic) the main#4ml *ile an type the coe belo'

  • 7/23/2019 Mobile Application Lab

    4/53

    894ml version:;1#0; encoin":;ut*anroi:;http>??schemas#anroi#com?ap)?res?anroi;

    anroi>layout@'ith:;*ill@parent; anroi>layout@hei"ht:;*ill@parent;

    anroi>orientation:;vertical; =

    8e4tBie' anroi>i:;i?te4tBie'1;

    anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;'rap@content; anroi>layout@mar"in:;!0sp;

    anroi>"ravity:;center;

    anroi>te4t:;ELL2 &2+LD;

    anroi>te4tSie:;!0sp; anroi>te4tStyle:;bol; ?=

    8utton

    anroi>i:;i?button1;

    anroi>layout@'ith:;match@parent; anroi>layout@hei"ht:;'rap@content;

    anroi>"ravity:;center; anroi>te4t:;Chan"e *ont sie;

    anroi>te4tSie:;!0sp; ?=

    8utton anroi>i:;i?button!;

    anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;'rap@content;

    anroi>"ravity:;center; anroi>te4t:;Chan"e color;

    anroi>te4tSie:;!0sp; ?=

    8utton anroi>i:;i?button$;

    anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;'rap@content; anroi>"ravity:;center;

    anroi>te4t:;Chan"e *ont;

    anroi>te4tSie:;!0sp; ?=

    8?LinearLayout=/A"ain clic) the "raphics layout tab an screen layout is loo) li)e belo'

  • 7/23/2019 Mobile Application Lab

    5/53

    10Go to pro3ect e4plorer an select src *oler#7o' select mainactivity#3ava *ile an type the*ollo'in" coe

    .+2G+AM

    ??import anroi#+H

    import anroi#app#ActivityH

    import anroi#"raphics#ColorHimport anroi#"raphics#ype*aceH

    import anroi#os#unleH

    import anroi#vie'#Bie'H

    import anroi#'i"et#uttonHimport anroi#'i"et#e4tBie'H

    public class AnroiActivity e4tens Activity

    *loat *ont :!%H

    int i:1H

    2verrie

    public voi onCreate5unle saveInstanceState

    super#onCreate5saveInstanceStateH

    setContentBie'5+#layout#mainH

    *inal e4tBie' t1:5e4tBie' *inBie'yI5+#i#te4tBie'1H utton b1 : 5utton *inBie'yI5+#i#button1H

    b1#set2nClic)Listener5ne' Bie'#2nClic)Listener5

    public voi onClic)5Bie' vie' t1#sete4tSie5*ontH

    *ont:*ont%H

  • 7/23/2019 Mobile Application Lab

    6/53

    i*5*ont::%0

    *ont:!0H

    J JH

    utton b! : 5utton *inBie'yI5+#i#button!H

    b!#set2nClic)Listener5ne' Bie'#2nClic)Listener5 public voi onClic)5Bie' vie'

    s'itch5i

    case 1>

    t1#sete4tColor5Color#parseColor5;K0000FF;H

    brea)H

    case !> t1#sete4tColor5Color#parseColor5;K00FF00;H

    brea)H

    case $>

    t1#sete4tColor5Color#parseColor5;KFF0000;H brea)H

    case %> t1#sete4tColor5Color#parseColor5;K-00000;H

    brea)H

    J iH

    i*5i::(

    i:1H

    J

    JH

    J

    J117o' "o to main#4ml an ri"ht clic) #select run as option an select run con*i"uration

  • 7/23/2019 Mobile Application Lab

    7/53

    1! Anroi output is present in the anroi emulator as sho'n in belo'#

  • 7/23/2019 Mobile Application Lab

    8/53

    ). Develop an application that uses *a+out "ana$ers and event listeners.

    12pen eclipse or anroi stuio an select ne' anroi pro3ect!Give pro3ect name an select ne4t

    $ Choose the anroi version#Choose the lo'est anroi version5Anroi !#! an select ne4t

    % nter the pac)a"e name#pac)a"e name must be t'o 'or seprate by comma an clic) *inish(Go to pac)a"e e4plorer in the le*t han sie#select our pro3ect#

    6Go to res *oler an select layout#Double clic) the main#4ml *ile#A the coe belo'

    8+elativeLayout 4mlns>anroi:;http>??schemas#anroi#com?ap)?res?anroi;

    anroi>i:;i?relativeLayout1;

    anroi>layout@'ith:;*ill@parent;

    anroi>layout@hei"ht:;*ill@parent; =

    8LinearLayout

    anroi>i:;i?linearLayout1;

    anroi>layout@'ith:;'rap@content; anroi>layout@hei"ht:;'rap@content;

    anroi>layout@ali"n.arentLe*t:;true; anroi>layout@ali"n.arent+i"ht:;true;

    anroi>layout@ali"n.arentop:;true; =

    8e4tBie'

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content;

    anroi>layout@"ravity:;center; anroi>te4t:;ADDII27;

    anroi>te4tSie:;!0p; =

    8?e4tBie'=

    8?LinearLayout=

    8LinearLayout anroi>i:;i?linearLayout!;

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content;

    anroi>layout@ali"n.arentLe*t:;true; anroi>layout@ali"n.arent+i"ht:;true;

    anroi>layout@belo':;i?linearLayout1; =

    8e4tBie' anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content;

    anroi>te4t:;7+ 72 1; = 8?e4tBie'=

    8ite4t

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content;

  • 7/23/2019 Mobile Application Lab

    9/53

    anroi>layout@'ei"ht:;0#!0;

    anroi>i:;i?eitte4t1;

    anroi>inputype:;number;= 8?ite4t=

    8?LinearLayout=

    8LinearLayout anroi>i:;i?linearLayout$;

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content; anroi>layout@ali"n.arentLe*t:;true;

    anroi>layout@ali"n.arent+i"ht:;true;

    anroi>layout@belo':;i?linearLayout!; =

    8e4tBie' anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content;

    anroi>te4t:;7+ 72 !; =

    8?e4tBie'=8ite4t

    anroi>layout@'ith:;'rap@content; anroi>layout@hei"ht:;'rap@content;

    anroi>layout@'ei"ht:;0#!0;

    anroi>i:;i?eitte4t!; anroi>inputype:;number;=

    8?ite4t=

    8?LinearLayout=

    8LinearLayout anroi>i:;i?linearLayout%;

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content; anroi>layout@ali"n.arentLe*t:;true;

    anroi>layout@ali"n.arent+i"ht:;true;

    anroi>layout@belo':;i?linearLayout$; =

    8utton

    anroi>layout@'ith:;'rap@content;

    anroi>i:;i?button1; anroi>layout@hei"ht:;'rap@content;

    anroi>te4t:;Aition;

    anroi>layout@'ei"ht:;0#(0; ?=8utton

    anroi>layout@'ith:;'rap@content;

    anroi>i:;i?button$; anroi>layout@hei"ht:;'rap@content;

    anroi>te4t:;subtraction;

    anroi>layout@'ei"ht:;0#(0; ?=

    8utton

  • 7/23/2019 Mobile Application Lab

    10/53

    anroi>layout@'ith:;'rap@content;

    anroi>i:;i?button!;

    anroi>layout@hei"ht:;'rap@content; anroi>te4t:;CLA+;

    anroi>layout@'ei"ht:;0#(0; ?=

    8?LinearLayout=8Bie'

    anroi>layout@hei"ht:;!p4;

    anroi>layout@'ith:;*ill@parent; anroi>layout@belo':;i?linearLayout%;

    anroi>bac)"roun:;KDDFFDD;?=

    8?+elativeLayout=

    7o' select mainactivity#3ava *ile an type the *ollo'in" coe#pac)a"e layout#neH

    import anroi#app#ActivityHimport anroi#os#unleH

    import anroi#vie'#Bie'Himport anroi#vie'#Bie'#2nClic)ListenerH

    import anroi#'i"et#uttonH

    import anroi#'i"et#ite4tHimport anroi#'i"et#oastH

    public class LA2UActivity e4tens Activity

    ? Calle 'hen the activity is *irst create# ? ite4t t4tData1,t4tData!H

    *loat num1,num!,result1,result!H

    2verrie public voi onCreate5unle saveInstanceState

    super#onCreate5saveInstanceStateH

    setContentBie'5+#layout#mainH

    utton a : 5utton *inBie'yI5+#i#button1H

    a#set2nClic)Listener5ne' 2nClic)Listener5 public voi onClic)5Bie' v

    try

    t4tData1 : 5ite4t *inBie'yI5+#i#eitte4t1H

    t4tData! : 5ite4t *inBie'yI5+#i#eitte4t!H

    num1 : Float#parseFloat5t4tData1#"ete4t5#toStrin"5H num! : Float#parseFloat5t4tData!#"ete4t5#toStrin"5H

    result1:num1num!H

    oast#ma)ee4t5"etaseConte4t5,;A7S&+>;result1,oast#L7GE@SE2+#sho'5H

  • 7/23/2019 Mobile Application Lab

    11/53

    J

    catch54ception e

    oast#ma)ee4t5"etaseConte4t5, e#"etMessa"e5,

    oast#L7GE@SE2+#sho'5H

    J J

    JH

    utton sub : 5utton *inBie'yI5+#i#button$H sub#set2nClic)Listener5ne' 2nClic)Listener5

    public voi onClic)5Bie' v

    try

    t4tData1 : 5ite4t *inBie'yI5+#i#eitte4t1H

    t4tData! : 5ite4t *inBie'yI5+#i#eitte4t!H

    num1 : Float#parseFloat5t4tData1#"ete4t5#toStrin"5H num! : Float#parseFloat5t4tData!#"ete4t5#toStrin"5H

    result!:num1

  • 7/23/2019 Mobile Application Lab

    12/53

    J

    JH

    J

    J

    -7o' "o to main#4ml an ri"ht clic) #select run as option an select run con*i"uration/ Anroi output is present in the anroi emulator as sho'n in belo'#

  • 7/23/2019 Mobile Application Lab

    13/53

    . Develop a native calculator application

    Main#4ml coin"

    894ml version:;1#0; encoin":;ut*anroi:;http>??schemas#anroi#com?ap)?res?anroi;

    anroi>orientation:;vertical;

    anroi>layout@'ith:;*ill@parent;

    anroi>layout@hei"ht:;*ill@parent;=8LinearLayout

    anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;'rap@content;anroi>i:;i?linearLayout1;

    anroi>layout@mar"inLe*t:;10pt;anroi>layout@mar"in+i"ht:;10pt;anroi>layout@mar"inop:;$pt;=

    8ite4t

    anroi>layout@'ei"ht:;1;

    anroi>layout@hei"ht:;'rap@content;anroi>layout@mar"in+i"ht:;(pt;

    anroi>i:;i?et7um1;

    anroi>layout@'ith:;match@parent;anroi>inputype:;numberDecimal;=

    8?ite4t=

    8ite4tanroi>layout@hei"ht:;'rap@content;

    anroi>layout@'ei"ht:;1;

    anroi>layout@mar"inLe*t:;(pt;anroi>i:;i?et7um!;

    anroi>layout@'ith:;match@parent;

    anroi>inputype:;numberDecimal;=

    8?ite4t=8?LinearLayout=

    8LinearLayout

    anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;'rap@content;anroi>i:;i?linearLayout!;

    anroi>layout@mar"inop:;$pt;anroi>layout@mar"inLe*t:;(pt;

    anroi>layout@mar"in+i"ht:;(pt;=

    8utton

    anroi>layout@hei"ht:;'rap@content;anroi>layout@'ith:;match@parent;

  • 7/23/2019 Mobile Application Lab

    14/53

    anroi>layout@'ei"ht:;1;

    anroi>te4t:;;

    anroi>te4tSie:;1(pt;anroi>i:;i?btnA;=

    8?utton=

    8uttonanroi>layout@hei"ht:;'rap@content;

    anroi>layout@'ith:;match@parent;

    anroi>layout@'ei"ht:;1;anroi>te4t:;te4tSie:;1(pt;

    anroi>i:;i?btnSub;=

    8?utton=8utton

    anroi>layout@hei"ht:;'rap@content;

    anroi>layout@'ith:;match@parent;

    anroi>layout@'ei"ht:;1;anroi>te4t:;;

    anroi>te4tSie:;1(pt;anroi>i:;i?btnMult;=

    8?utton=

    8uttonanroi>layout@hei"ht:;'rap@content;

    anroi>layout@'ith:;match@parent;

    anroi>layout@'ei"ht:;1;

    anroi>te4t:;?;anroi>te4tSie:;1(pt;

    anroi>i:;i?btnDiv;=

    8?utton=8?LinearLayout=

    8e4tBie'

    anroi>layout@hei"ht:;'rap@content;anroi>layout@'ith:;match@parent;

    anroi>layout@mar"inLe*t:;(pt;

    anroi>layout@mar"in+i"ht:;(pt;

    anroi>te4tSie:;1!pt;anroi>layout@mar"inop:;$pt;

    anroi>i:;i?tv+esult;

    anroi>"ravity:;center@horiontal;=8?e4tBie'=

    8?LinearLayout=

    MainActivity#3ava coin"

    pac)a"e CALCU#CALUH

    import anroi#app#ActivityH

  • 7/23/2019 Mobile Application Lab

    15/53

    import anroi#os#unleH

    import anroi#te4t#e4tUtilsH

    import anroi#vie'#Bie'Himport anroi#vie'#Bie'#2nClic)ListenerH

    import anroi#'i"et#uttonH

    import anroi#'i"et#ite4tHimport anroi#'i"et#e4tBie'H

    public class CALCULA2+Activity e4tens Activity implements 2nClic)Listener ite4t input1H

    ite4t input!H

    utton aitionH utton subtractionH

    utton multiplicationH

    utton ivisionH

    e4tBie' tv+esultH

    Strin" oper : ;;H

    2verrie public voi onCreate5unle saveInstanceState

    super#onCreate5saveInstanceStateH

    setContentBie'5+#layout#mainH

    input1 : 5ite4t *inBie'yI5+#i#et7um1H input! : 5ite4t *inBie'yI5+#i#et7um!H

    aition : 5utton *inBie'yI5+#i#btnAH subtraction : 5utton *inBie'yI5+#i#btnSubH

    multiplication : 5utton *inBie'yI5+#i#btnMultH

    ivision : 5utton *inBie'yI5+#i#btnDivH

    tv+esult : 5e4tBie' *inBie'yI5+#i#tv+esultH

    ?? set a listener aition#set2nClic)Listener5thisH

    subtraction#set2nClic)Listener5thisH

    multiplication#set2nClic)Listener5thisH ivision#set2nClic)Listener5thisH

    J

    2verrie

    public voi onClic)5Bie' v

    ?? 2D2 Auto

  • 7/23/2019 Mobile Application Lab

    16/53

    *loat num1 : 0H

    *loat num! : 0H

    *loat result : 0H

    ?? chec) i* the *iels are empty

    i* 5e4tUtils#ismpty5input1#"ete4t5#toStrin"5 NN e4tUtils#ismpty5input!#"ete4t5#toStrin"5

    returnH

    J

    ?? rea ite4t an *ill variables 'ith numbers

    num1 : Float#parseFloat5input1#"ete4t5#toStrin"5H

    num! : Float#parseFloat5input!#"ete4t5#toStrin"5H

    ?? e*ines the button that has been clic)e an per*orms the corresponin" operation

    ?? 'rite operation into oper, 'e 'ill use it later *or output

    s'itch 5v#"etI5 case +#i#btnA>

    oper : ;;H result : num1 num!H

    brea)H

    case +#i#btnSub> oper : ; oper : ;;H

    result : num1 num!H

    brea)H case +#i#btnDiv>

    oper : ;?;H

    result : num1 ? num!H brea)H

    e*ault>

    brea)H

    J

    ?? *orm the output line

    tv+esult#sete4t5num1 ; ; oper ; ; num! ; : ; resultH J

    J2utput

  • 7/23/2019 Mobile Application Lab

    17/53

  • 7/23/2019 Mobile Application Lab

    18/53

    -. rite an application that dra(s /asic $raphical primitives on the screen in

    android

    1# 2pen eclipse or anroi stuio an select ne' anroi pro3ect!# Give pro3ect name an select ne4t

    $# Choose the anroi version#Choose the lo'est anroi version5Anroi !#! an selectne4t

    %# nter the pac)a"e name#pac)a"e name must be t'o 'or seprate by comma an clic)*inish

    (# Go to pac)a"e e4plorer in the le*t han sie#select our pro3ect#

    6# Go to res *oler an select layout#Double clic) the main#4ml *ile#DonOt chan"e anythin"in layout#Leave as e*ault#

    # 7o' select mainactivity#3ava *ile an type the *ollo'in" coe#

    pac)a"e asic#primitiveH

    import anroi#app#ActivityHimport anroi#content#Conte4tHimport anroi#"raphics#CanvasH

    import anroi#"raphics#ColorH

    import anroi#"raphics#.aintHimport anroi#os#unleH

    import anroi#vie'#Bie'H

    public class asicprimitiveActivity e4tens Activity

    ? Calle 'hen the activity is *irst create# ?

    2verrie

    public voi onCreate5unle saveInstanceState super#onCreate5saveInstanceStateH

    setContentBie'5ne' myvie'5thisH

    J private class myvie' e4tens Bie'

    public myvie'5Conte4t conte4t

    super5conte4tH

    J 2verrie

    protecte voi onDra'5Canvas canvas

    super#onDra'5canvasH

    .aint paint:ne' .aint5H

    paint#sete4tSie5%0H paint#setColor5Color#G+7H

    canvas#ra'e4t5;Circle;, ((, $0, paintH

  • 7/23/2019 Mobile Application Lab

    19/53

    paint#setColor5Color#+DH

    canvas#ra'Circle5100, 1(0,100, paintH

    paint#setColor5Color#G+7H canvas#ra'e4t5;+ectan"le;, !((, $0, paintH

    paint#setColor5Color#LL2&H

    canvas#ra'+ect5!(0, (0,%00,$(0, paintH paint#setColor5Color#G+7H

    canvas#ra'e4t5;SPUA+;, ((, %$0, paintH

    paint#setColor5Color#LUH canvas#ra'+ect5(0, %(0,1(0,((0, paintH

    paint#setColor5Color#G+7H

    canvas#ra'e4t5;LI7;, !((, %$0, paintH

    paint#setColor5Color#CA7H canvas#ra'Line5!(0, (00, $(0, (00, paintH

    J

    JJ

    -7o' "o to main#4ml an ri"ht clic) #select run as option an select run con*i"uration/ Anroi output is present in the anroi emulator as sho'n in belo'#

  • 7/23/2019 Mobile Application Lab

    20/53

    0. Develop an application that maes use o% data/ase

    12pen eclipse or anroi stuio an select ne' anroi pro3ect!Give pro3ect name an select ne4t

    $ Choose the anroi version#Choose the lo'est anroi version5Anroi !#! an select ne4t

    % nter the pac)a"e name#pac)a"e name must be t'o 'or seprate by comma an clic) *inish(Go to pac)a"e e4plorer in the le*t han sie#select our pro3ect#

    6Go to res *oler an select layout#Double clic) the main#4ml *ile#A the coe belo'

    894ml version:;1#0; encoin":;ut*anroi:;http>??schemas#anroi#com?ap)?res?anroi;

    anroi>i:;i?myLayout;

    anroi>stretchColumns:;0; anroi>layout@'ith:;*ill@parent;

    anroi>layout@hei"ht:;*ill@parent;=

    8e4tBie' anroi>te4t:;strin"?title;

    anroi>layout@4:;110p; anroi>layout@y:;10p;

    anroi>layout@'ith:;'rap@content; anroi>layout@hei"ht:;'rap@content;?=

    8e4tBie' anroi>te4t:;strin"?empi;

    anroi>layout@4:;$0p; anroi>layout@y:;(0p;

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content;?=

    8ite4t anroi>i:;i?eitmpi; anroi>inputype:;number;

    anroi>layout@4:;1(0p; anroi>layout@y:;(0p; anroi>layout@'ith:;1(0p;

    anroi>layout@hei"ht:;%0p;?=

    8e4tBie' anroi>te4t:;strin"?name; anroi>layout@4:;$0p;

    anroi>layout@y:;100p;

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content;?= 8ite4t anroi>i:;i?eit7ame;

    anroi>inputype:;te4t;

    anroi>layout@4:;1(0p; anroi>layout@y:;100p;

    anroi>layout@'ith:;1(0p;

    anroi>layout@hei"ht:;%0p;?= 8e4tBie' anroi>te4t:;strin"?salary;

    anroi>layout@4:;$0p;

    anroi>layout@y:;1(0p;

    anroi>layout@'ith:;'rap@content;

  • 7/23/2019 Mobile Application Lab

    21/53

    anroi>layout@hei"ht:;'rap@content;?=

    8ite4t anroi>i:;i?eitsalary;

    anroi>inputype:;number;anroi>layout@4:;1(0p;

    anroi>layout@y:;1(0p;

    anroi>layout@'ith:;1(0p; anroi>layout@hei"ht:;%0p;?=

    8utton anroi>i:;i?btnA;

    anroi>te4t:;strin"?a; anroi>layout@4:;$0p;

    anroi>layout@y:;!00p;

    anroi>layout@'ith:;1$0p;

    anroi>layout@hei"ht:;%0p;?= 8utton anroi>i:;i?btnDelete;

    anroi>te4t:;strin"?elete;

    anroi>layout@4:;160p;

    anroi>layout@y:;!00p; anroi>layout@'ith:;1$0p;

    anroi>layout@hei"ht:;%0p;?=n 8utton anroi>i:;i?btnMoi*y;

    anroi>te4t:;strin"?moi*y;

    anroi>layout@4:;$0p; anroi>layout@y:;!(0p;

    anroi>layout@'ith:;1$0p;

    anroi>layout@hei"ht:;%0p;?=

    8utton anroi>i:;i?btnBie'; anroi>te4t:;strin"?vie';

    anroi>layout@4:;160p;

    anroi>layout@y:;!(0p; anroi>layout@'ith:;1$0p;

    anroi>layout@hei"ht:;%0p;?=

    8utton anroi>i:;i?btnBie'All; anroi>te4t:;strin"?vie'@all;

    anroi>layout@4:;-(p;

    anroi>layout@y:;$00p;

    anroi>layout@'ith:;1(0p; anroi>layout@hei"ht:;%0p;?=

    8?AbsoluteLayout=Go to values *oler an select strin"#4ml *ile#+eplace the coe belo'

    894ml version:;1#0; encoin":;ut*

  • 7/23/2019 Mobile Application Lab

    22/53

    8strin" name:;title;=mployee Details8?strin"=

    8strin" name:;empi;=nter mployee ID> 8?strin"=

    8strin" name:;name;=nter 7ame> 8?strin"= 8strin" name:;salary;=nter salary> 8?strin"=

    8strin" name:;a;=A mployee8?strin"=

    8strin" name:;elete;=Delete mployee8?strin"= 8strin" name:;moi*y;=Moi*y mployee8?strin"=

    8strin" name:;vie';=Bie' mployee8?strin"=

    8strin" name:;vie'@all;=Bie' All mployee8?strin"=

    8?resources=

    - 7o' select mainactivity#3ava *ile an type the *ollo'in" coe#In my coin" maniactivity name

    is mployeeetailActivity#pac)a"e employee#etailH

    ??import anroi#+H

    import anroi#app#ActivityH

    import anroi#app#AlertDialo"#uilerHimport anroi#content#Conte4tH

    import anroi#atabase#CursorHimport anroi#atabase#sRlite#SPLiteDatabaseH

    import anroi#os#unleH

    import anroi#vie'#Bie'Himport anroi#vie'#Bie'#2nClic)ListenerH

    import anroi#'i"et#uttonH

    import anroi#'i"et#ite4tH

    public class mployeeetailActivity e4tens Activity implements 2nClic)Listener

    ite4t eitmpi,eit7ame,eitsalaryH

    utton btnA,btnDelete,btnMoi*y,btnBie',btnBie'AllH SPLiteDatabase bH

    ? Calle 'hen the activity is *irst create# ?

    2verrie public voi onCreate5unle saveInstanceState

    super#onCreate5saveInstanceStateH

    setContentBie'5+#layout#mainH eitmpi:5ite4t*inBie'yI5+#i#eitmpiH

    eit7ame:5ite4t*inBie'yI5+#i#eit7ameH

    eitsalary:5ite4t*inBie'yI5+#i#eitsalaryH btnA:5utton*inBie'yI5+#i#btnAH

    btnDelete:5utton*inBie'yI5+#i#btnDeleteH

    btnMoi*y:5utton*inBie'yI5+#i#btnMoi*yH btnBie':5utton*inBie'yI5+#i#btnBie'H

    btnBie'All:5utton*inBie'yI5+#i#btnBie'AllH

    btnA#set2nClic)Listener5thisH

    btnDelete#set2nClic)Listener5thisH

  • 7/23/2019 Mobile Application Lab

    23/53

    btnMoi*y#set2nClic)Listener5thisH

    btnBie'#set2nClic)Listener5thisH

    btnBie'All#set2nClic)Listener5thisH b:open2rCreateDatabase5;mployeeD;, Conte4t#M2D@.+IBA, nullH

    b#e4ecSPL5;C+A AL IF 72 ISS employee5empi BA+CEA+,name

    BA+CEA+,salary BA+CEA+H;H J

    public voi onClic)5Bie' vie'

    i*5vie'::btnA

    i*5eitmpi#"ete4t5#toStrin"5#trim5#len"th5::0NN

    eit7ame#"ete4t5#toStrin"5#trim5#len"th5::0NN eitsalary#"ete4t5#toStrin"5#trim5#len"th5::0

    sho'Messa"e5;rror;, ;.lease enter all values;H

    returnH J

    b#e4ecSPL5;I7S+ I72 employee BALUS5O;eitmpi#"ete4t5;O,O;eit7ame#"ete4t5

    ;O,O;eitsalary#"ete4t5;OH;H

    sho'Messa"e5;Success;, ;+ecor ae;H cleare4t5H

    J

    i*5vie'::btnDelete

    i*5eitmpi#"ete4t5#toStrin"5#trim5#len"th5::0

    sho'Messa"e5;rror;, ;.lease enter mployee i;H returnH

    J

    Cursor c:b#ra'Puery5;SLC F+2M employee &E+empi:O;eitmpi#"ete4t5;O;, nullH

    i*5c#moveoFirst5

    b#e4ecSPL5;DL F+2M employee &E+ empi:O;eitmpi#"ete4t5;O;H

    sho'Messa"e5;Success;, ;+ecor Delete;H

    J else

    sho'Messa"e5;rror;, ;Invali mployee i;H J

    cleare4t5H

    J

    i*5vie'::btnMoi*y

  • 7/23/2019 Mobile Application Lab

    24/53

    i*5eitmpi#"ete4t5#toStrin"5#trim5#len"th5::0

    sho'Messa"e5;rror;, ;.lease enter mployee i;H

    returnH

    J Cursor c:b#ra'Puery5;SLC F+2M employee &E+

    empi:O;eitmpi#"ete4t5;O;, nullH

    i*5c#moveoFirst5

    b#e4ecSPL5;U.DA employee S name:O;eit7ame#"ete4t5

    ;O,salary:O;eitsalary#"ete4t5

    ;O &E+ empi:O;eitmpi#"ete4t5;O;H sho'Messa"e5;Success;, ;+ecor Moi*ie;H

    J

    else

    sho'Messa"e5;rror;, ;Invali +ollno;H

    J cleare4t5H

    J

    i*5vie'::btnBie'

    i*5eitmpi#"ete4t5#toStrin"5#trim5#len"th5::0

    sho'Messa"e5;rror;, ;.lease enter mployee i;H returnH

    J

    Cursor c:b#ra'Puery5;SLC F+2M employee &E+empi:O;eitmpi#"ete4t5;O;, nullH

    i*5c#moveoFirst5

    eit7ame#sete4t5c#"etStrin"51H

    eitsalary#sete4t5c#"etStrin"5!H

    J

    else

    sho'Messa"e5;rror;, ;Invali mployee i;H

    cleare4t5H J

    J

    i*5vie'::btnBie'All

    Cursor c:b#ra'Puery5;SLC F+2M employee;, nullH

    i*5c#"etCount5::0

  • 7/23/2019 Mobile Application Lab

    25/53

    sho'Messa"e5;rror;, ;7o recors *oun;H

    returnH

    J Strin"u**er bu**er:ne' Strin"u**er5H

    'hile5c#moveo7e4t5

    bu**er#appen5;mployee i> ;c#"etStrin"50;Tn;H

    bu**er#appen5;7ame> ;c#"etStrin"51;Tn;H

    bu**er#appen5;salary> ;c#"etStrin"5!;TnTn;H J

    sho'Messa"e5;mployee etails Details;, bu**er#toStrin"5H

    J

    J

    public voi sho'Messa"e5Strin" title,Strin" messa"e

    uiler builer:ne' uiler5thisH builer#setCancelable5trueH

    builer#setitle5titleH builer#setMessa"e5messa"eH

    builer#sho'5H

    J public voi cleare4t5

    eitmpi#sete4t5;;H

    eit7ame#sete4t5;;H eitsalary#sete4t5;;H

    eitmpi#reRuestFocus5H

    JJ

    /7o' "o to main#4ml an ri"ht clic) #select run as option an select run con*i"uration

    10 Anroi output is present in the anroi emulator as sho'n in belo'#

  • 7/23/2019 Mobile Application Lab

    26/53

  • 7/23/2019 Mobile Application Lab

    27/53

    2. Implement an application that implements "ulti threadin$

    12pen eclipse or anroi stuio an select ne' anroi pro3ect!Give pro3ect name an select ne4t

    $ Choose the anroi version#Choose the lo'est anroi version5Anroi !#! an select ne4t

    % nter the pac)a"e name#pac)a"e name must be t'o 'or seprate by comma an clic) *inish(Go to pac)a"e e4plorer in the le*t han sie#select our pro3ect#

    6Go to res *oler an select layout#Double clic) the main#4ml *ile#A the coe belo'

    894ml version:;1#0; encoin":;ut*anroi:;http>??schemas#anroi#com?ap)?res?anroi;

    anroi>layout@'ith:;match@parent; anroi>layout@hei"ht:;match@parent;

    anroi>orientation:;vertical;

    anroi>i:;i?in*o; = 8utton

    anroi>i:;i?button1; anroi>layout@'ith:;match@parent; anroi>layout@hei"ht:;'rap@content;

    anroi>onClic):;*etchData;

    anroi>te4t:;Start MULIE+AD; ?=

    8e4tBie' anroi>i:;i?te4tBie'1;

    anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content; anroi>te4t:;Main threa; ?=

    8?LinearLayout=

    7o' select mainactivity#3ava *ile an type the *ollo'in" coe#pac)a"e multi#threain"H

    ??import your#*irst#+Himport anroi#app#ActivityH

    import anroi#os#unleH

    import anroi#os#EanlerH

    import anroi#vie'#Bie'Himport anroi#'i"et#e4tBie'H

    public class Multihreain"Activity e4tens Activity private e4tBie' tv2utputH

    private static *inal int t1 : 1H

    private static *inal int t! : !H private static *inal int t$ : $H

    2verrie

    public voi onCreate5unle saveInstanceState

    super#onCreate5saveInstanceStateH setContentBie'5+#layout#mainH

  • 7/23/2019 Mobile Application Lab

    28/53

    tv2utput : 5e4tBie' *inBie'yI5+#i#te4tBie'1H

    J public voi *etchData5Bie' v

    tv2utput#sete4t5;Main threa;H

    threa1#start5H threa!#start5H

    threa$#start5H

    J

    hrea threa1 : ne' hrea5ne' +unnable5

    2verrie public voi run5

    *or 5int i : 0H i 8 (H i

    try

    hrea#sleep51000H J catch 5Interrupte4ception e

    e#printStac)race5H J

    hanler#senmptyMessa"e5t1H

    J

    J

    JH

    hrea threa! : ne' hrea5ne' +unnable5

    2verrie

    public voi run5 *or 5int i : 0H i 8 (H i

    try

    hrea#sleep51000H J catch 5Interrupte4ception e

    e#printStac)race5H

    J

    hanler#senmptyMessa"e5t!H J

    J JH

    hrea threa$ : ne' hrea5ne' +unnable5

    2verrie

    public voi run5

    *or 5int i : 0H i 8 (H i

    try

  • 7/23/2019 Mobile Application Lab

    29/53

    hrea#sleep51000H

    J catch 5Interrupte4ception e

    e#printStac)race5H J

    hanler#senmptyMessa"e5t$H

    J

    J

    JH

    Eanler hanler : ne' Eanler5

    public voi hanleMessa"e5anroi#os#Messa"e ms"

    i*5ms"#'hat :: t1 tv2utput#appen5;TnIn threa 1;H

    J

    i*5ms"#'hat :: t!

    tv2utput#appen5;TnIn threa !;H J

    i*5ms"#'hat :: t$ tv2utput#appen5;TnIn threa $;H

    J

    J JH

    J

    -7o' "o to main#4ml an ri"ht clic) #select run as option an select run con*i"uration

    / Anroi output is present in the anroi emulator as sho'n in belo'#

  • 7/23/2019 Mobile Application Lab

    30/53

  • 7/23/2019 Mobile Application Lab

    31/53

    3. Develop a native application that uses GS location in%ormation.

    12pen eclipse or anroi stuio an select ne' anroi pro3ect!Give pro3ect name an select ne4t

    $ Choose the anroi version#Choose the lo'est anroi version5Anroi !#! an select ne4t

    % nter the pac)a"e name#pac)a"e name must be t'o 'or seprate by comma an clic) *inish(Go to pac)a"e e4plorer in the le*t han sie#select our pro3ect#

    6Go to res *oler an select layout#Double clic) the main#4ml *ile#A the coe belo'

    894ml version:;1#0; encoin":;ut*anroi:;http>??schemas#anroi#com?ap)?res?anroi;

    anroi>i:;i?relativeLayout1; anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;match@parent; =

    8utton

    anroi>i:;i?sho'@Location; anroi>layout@'ith:;'rap@content;

    anroi>layout@hei"ht:;'rap@content anroi>te4t:;Sho'@Location;

    anroi>layout@centerBertical:;true;

    anroi>layout@centerEoriontal:;true; ?=

    8?+elativeLayout=

    7o' select mainactivity#3ava *ile an type the *ollo'in" coe#In my coin" maniactivity nameis G.SlocationActivity#

    pac)a"e "ps#locationH

    ??import anroi#+Himport anroi#app#ActivityH

    import anroi#os#unleH

    import anroi#vie'#Bie'H

    import anroi#'i"et#uttonHimport anroi#'i"et#oastH

    public class G.SlocationActivity e4tens Activity ? Calle 'hen the activity is *irst create# ?

    utton btnSho'LocationH

    G.Strace "psH 2verrie

    public voi onCreate5unle saveInstanceState

    super#onCreate5saveInstanceStateH

    setContentBie'5+#layout#mainH btnSho'Location:5utton*inBie'yI5+#i#sho'@LocationH

  • 7/23/2019 Mobile Application Lab

    32/53

    btnSho'Location#set2nClic)Listener5ne' Bie'#2nClic)Listener5

    2verrie

    public voi onClic)5Bie' v ?? 2D2 Auto

  • 7/23/2019 Mobile Application Lab

    33/53

    import anroi#content#Conte4tH

    import anroi#content#Dialo"Inter*aceH

    import anroi#content#IntentHimport anroi#location#LocationH

    import anroi#location#LocationListenerH

    import anroi#location#LocationMana"erHimport anroi#os#unleH

    import anroi#os#IinerH

    import anroi#provier#Settin"sH

    public class G.Strace e4tens Service implements LocationListener

    private *inal Conte4t conte4tH

    boolean isG.Snable:*alseHboolean canGetLocation:*alseH

    boolean is7et'or)nable:*alseH

    Location locationH

    ouble latitueHouble lon"titueH

    private static *inal lon" MI7@DISA7C@CEA7G@[email protected]:10Hprivate static *inal lon" MI7@IM@&@U.DAS:1000601H

    protecte LocationMana"er locationMana"erH

    public G.Strace5Conte4t conte4t

    this#conte4t:conte4tH

    "etLocation5H

    Jpublic Location "etLocation5

    try locationMana"er:5LocationMana"er conte4t#"etSystemService5L2CAI27@S+BICH

    isG.Snable:locationMana"er#is.roviernable5LocationMana"er#G.S@.+2BID+H

    is7et'or)nable:locationMana"er#is.roviernable5LocationMana"er#7&2+@.+2BI

    D+H

    i*5QisG.Snable VV Qis7et'or)nable

    Jelse

    this#canGetLocation:trueH

    i*5is7et'or)nable

    locationMana"er#reRuestLocationUpates5

    LocationMana"er#7&2+@.+2BID+, MI7@IM@&@U.DAS,

    MI7@DISA7C@CEA7G@[email protected],thisH

    J

  • 7/23/2019 Mobile Application Lab

    34/53

    i*5locationMana"erQ:null

    location:locationMana"er#"etLastno'nLocation5LocationMana"er#7&2+@.+2BID+H i*5location Q:null

    latitue:location#"etLatitue5H

    lon"titue:location#"etLon"itue5H

    J

    J J

    i*5isG.Snable

    i*5location::null

    locationMana"er#reRuestLocationUpates5LocationMana"er#G.S@.+2BID+,MI7@IM@&

    @U.DAS, MI7@DISA7C@CEA7G@[email protected], thisH

    i*5locationMana"erQ:null

    location:locationMana"er#"etLastno'nLocation5LocationMana"er#G.S@.+2BID+H

    i*5locationQ:null latitue:location#"etLatitue5H

    lon"titue:location#"etLon"itue5H

    J J

    J

    J

    J

    catch54ception e

    e#printStac)race5H

    J

    return locationHJ

    public voi stopUsin"G.S5

    i*5locationMana"erQ:null

    locationMana"er#removeUpates5G.Strace#thisH J

    J

    public ouble "etLatitue5 i*5locationQ:null

    latitue:location#"etLatitue5H

    J return latitueH

    J

    public ouble "etLon"tiue5

    i*5locationQ:null

  • 7/23/2019 Mobile Application Lab

    35/53

    lon"titue:location#"etLatitue5H

    J

    return lon"titueHJ

    public boolean canGetLocation5

    return this#canGetLocationHJ

    public voi sho'Settin"Alert5

    AlertDialo"#uiler alertDialo":ne' AlertDialo"#uiler5conte4tH alertDialo"#setitle5;G.S is settin"s;H

    alertDialo"#setMessa"e5;G.S is not enable#Do you 'ant to "o to settin" menu9;H

    alertDialo"#set.ositiveutton5;settin"s;, ne' Dialo"Inter*ace#2nClic)Listener5

    2verrie public voi onClic)5Dialo"Inter*ace ialo",int 'hich

    Intent intent:ne' Intent5Settin"s#ACI27@L2CAI27@S2U+C@SI7GSH

    conte4t#startActivity5intentH

    J JH

    alertDialo"#set7e"ativeutton5;cancel;, ne' Dialo"Inter*ace#2nClic)Listener5

    2verrie public voi onClic)5Dialo"Inter*ace ialo", int 'hich

    ?? 2D2 Auto

  • 7/23/2019 Mobile Application Lab

    36/53

    ?? 2D2 Auto

  • 7/23/2019 Mobile Application Lab

    37/53

    4. Implement an application that (rites data to the SD card.

    12pen eclipse or anroi stuio an select ne' anroi pro3ect!Give pro3ect name an select ne4t

    $ Choose the anroi version#Choose the lo'est anroi version5Anroi !#! an select ne4t

    % nter the pac)a"e name#pac)a"e name must be t'o 'or seprate by comma an clic) *inish(Go to pac)a"e e4plorer in the le*t han sie#select our pro3ect#

    6Go to res *oler an select layout#Double clic) the main#4ml *ile#A the coe belo'

    894ml version:;1#0; encoin":;ut*anroi:;http>??schemas#anroi#com?ap)?res?anroi;

    anroi>layout@'ith:;*ill@parent;

    anroi>layout@hei"ht:;*ill@parent;

    anroi>bac)"roun:;K**0000**; anroi>orientation:;vertical; =

    8ite4t

    anroi>i:;i?eite4t1; anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;'rap@content; =

    8reRuestFocus ?=

    8?ite4t=

    8utton

    anroi>i:;i?button1;

    anroi>layout@'ith:;match@parent; anroi>layout@hei"ht:;'rap@content;

    anroi>te4t:;SAB DAA; ?=

    8utton

    anroi>i:;i?button!; anroi>layout@'ith:;match@parent;

    anroi>layout@hei"ht:;'rap@content;

    anroi>te4t:;SE2& DAA; ?=

    8e4tBie'

    anroi>i:;i?te4tBie'1;

    anroi>layout@'ith:;'rap@content; anroi>layout@hei"ht:;'rap@content;

    ?=

    8?LinearLayout=

    7o' select mainactivity#3ava *ile an type the *ollo'in" coe#

  • 7/23/2019 Mobile Application Lab

    38/53

    pac)a"e save#sH

    import 3ava#io#FileHimport 3ava#io#FileInputStreamH

    import 3ava#io#File7otFoun4ceptionH

    import 3ava#io#File2utputStreamHimport 3ava#io#I24ceptionH

    import 3ava#io#InputStream+eaerH

    import 3ava#io#2utputStream&riterHimport anroi#app#ActivityH

    import anroi#os#unleH

    import anroi#os#nvironmentH

    import anroi#vie'#Bie'Himport anroi#'i"et#uttonH

    import anroi#'i"et#ite4tH

    import anroi#'i"et#e4tBie'H

    import anroi#'i"et#oastH

    public class SaveatascarActivity e4tens Activity ? Calle 'hen the activity is *irst create# ?

    utton save,loaH

    ite4t messa"eH e4tBie' t1H

    Strin" Messa"e1H

    2verrie

    public voi onCreate5unle saveInstanceState super#onCreate5saveInstanceStateH

    setContentBie'5+#layout#mainH

    save:5utton *inBie'yI5+#i#button1H loa:5utton *inBie'yI5+#i#button!H

    messa"e:5ite4t *inBie'yI5+#i#eite4t1H

    t1:5e4tBie' *inBie'yI5+#i#te4tBie'1H save#set2nClic)Listener5ne' Bie'#2nClic)Listener5

    public voi onClic)5Bie' v

    ??Get messa"e *rom user store in messa"e1 variable

    Messa"e1 :messa"e#"ete4t5#toStrin"5H try

    ??Create a ne' *oler calle MyDirectory in SDCar

    File scar:nvironment#"et4ternalStora"eDirectory5H File irectory:ne' File5scar#"etAbsolute.ath5;?MyDirectory;H

    irectory#m)irs5H

    ??Create a ne' *ile name te4t*ile#t4t insie MyDirectory File *ile:ne' File5irectory,;te4t*ile#t4t;H

    ??Create File 2utputstream to rea the *ile

    File2utputStream *ou:ne' File2utputStream5*ileH

    2utputStream&riter os':ne' 2utputStream&riter5*ouH

  • 7/23/2019 Mobile Application Lab

    39/53

    try

    ??'rite a user ata to *ile

    os'#appen5Messa"e1H os'#*lush5H

    os'#close5H

    oast#ma)ee4t5"etaseConte4t5,;Data Save;,oast#L7GE@L27G#sho'5H

    Jcatch5I24ception e

    e#printStac)race5H J

    Jcatch 5File7otFoun4ception e

    e#printStac)race5H

    J J

    JH

    loa#set2nClic)Listener5ne' Bie'#2nClic)Listener5

    public voi onClic)5Bie' v try

    File scar:nvironment#"et4ternalStora"eDirectory5H File irectory:ne' File5scar#"etAbsolute.ath5;?MyDirectory;H

    File *ile:ne' File5irectory,;te4t*ile#t4t;H

    FileInputStream *is:ne' FileInputStream5*ileH InputStream+eaer isr:ne' InputStream+eaer5*isH

    charWX ata:ne' charW100XH

    Strin" *inal@ata:;;H

    int sieH try

    'hile55sie:isr#rea5ata=0

    ??rea a ata *rom *ile

    Strin" rea@ata:Strin"#copyBalue2*5ata,0,sieH

    *inal@ata:rea@ataH ata:ne' charW100XH

    J

    ??isplay the ata in output

    oast#ma)ee4t5"etaseConte4t5,;Messa"e>;*inal@ata,oast#L7GE@L27G#sho'5H

    Jcatch5I24ception e

    e#printStac)race5H J

    Jcatch 5File7otFoun4ception e

    e#printStac)race5H J

    J

    JH

  • 7/23/2019 Mobile Application Lab

    40/53

    J

    J

    -7e4t step is to set permission to 'rite ata in s car#So "o to AnroiMani*est#4ml *ile# Copy

    an paste the *ollo'in" coin"#he coe shoul come be*ore 8application= tab#

    8usesname:;anroi#permission#&+I@+7AL@S2+AG;=8?uses

  • 7/23/2019 Mobile Application Lab

    41/53

  • 7/23/2019 Mobile Application Lab

    42/53

    10 . Implement an application that creates an alert upon receiving a message in

    android

    1)Open eclipse or android studio and select new android project

    2)Give project name and select next

    3) Choose the android version.Choose the lowest android version!ndroid 2.2) andselect next

    ") #nter the pac$age name.pac$age name must %e two word seprated %& comma

    and clic$ 'nish

    ()Go to pac$age explorer in the let hand side.select our project.

    *)Go to res older and select la&out.+ou%le clic$ the main.xml 'le.!dd the code

    %elow

    ,-crolliew xmlns/androidhttp/schemas.android.comap$resandroid

    android/la&outwidth'llparent

    android/la&outheightwrapcontent

    android/scroll%arsvertical 4,5a%le6a&out

    android/la&outwidthmatchparent

    android/la&outheightwrapcontent

    android/shrin$Columns7 android/stretchColumns7

    android/%ac$ground80000004

    ,5a%le9ow

    android/la&outheightwrapcontent

    android/la&outwidthmatchparent

    android/gravit&centerhori:ontal4

    ,5extiew

    android/id;

  • 7/23/2019 Mobile Application Lab

    43/53

    android/la&outheightwrapcontent

    android/la&outwidthmatchparent

    android/gravit&centerhori:ontal4

    ,5extiew

    android/la&outwidthmatchparent

    android/la&outheightwrapcontent android/text-i:e1Dsp

    android/text1.C!E5I!6 O IF+I!

    android/la&outspan"

    android/padding1Ddip

    android/textColor84

    ,5a%le9ow4

    ,5a%le9ow

    android/id;

  • 7/23/2019 Mobile Application Lab

    44/53

    android/textHJ+#9B!+ 4

    ,9adioGroup4

    ,5a%le9ow4

    ,5a%le9ow

    android/la&outheightwrapcontent

    android/la&outwidthmatchparent android/gravit&centerhori:ontal4

    ,5extiew

    android/la&outwidthmatchparent

    android/la&outheightwrapcontent

    android/text-i:e1Dsp

    android/text2. C!E5I!6 O 9@--I!K

    android/la&outspan"

    android/padding1Ddip

    android/textColor84

    ,5a%le9ow4

    ,5a%le9ow

    android/id;

  • 7/23/2019 Mobile Application Lab

    45/53

    android/id;

  • 7/23/2019 Mobile Application Lab

    46/53

  • 7/23/2019 Mobile Application Lab

    47/53

    11. Write a mobile application that creates alarm clock

  • 7/23/2019 Mobile Application Lab

    48/53

    1. 5ndroid "ani%est

    5ndroid"ani%est.'ml

    &e nee to "ive uses

  • 7/23/2019 Mobile Application Lab

    49/53

  • 7/23/2019 Mobile Application Lab

    50/53

    'ulic st$tic Al$rmActivit/ inst$nce@ > return inst

    -Override 'ulic void on7t$rt@ > su'er.on7t$rt@ inst = t&is

    -Override 'rotected void onCre$te,undle s$ved2nst$nce7t$te@ > su'er.onCre$tes$ved2nst$nce7t$te@ setContent;ie+6.l$/out.$ctivit/_m/@ $l$rmime8ic)er = ime8ic)er@ ind;ie+,/2d6.id.$l$rmime8ic)er@ $l$rmext;ie+ = ext;ie+@ ind;ie+,/2d6.id.$l$rmext@ oggle,utton $l$rmoggle = oggle,utton@ind;ie+,/2d6.id.$l$rmoggle@ $l$rm$n$ger = Al$rm$n$ger@ get7/stem7erviceALA6_7E6;2CE@

    'ulic void onoggleClic)ed;ie+ vie+@ > i oggle,utton@ [email protected]&ec)ed@@ > Log.d"/Activit/"B "Al$rm On"@ C$lend$r c$lend$r = C$lend$r.get2nst$nce@ c$lend$r.setC$lend$r.5O46_O_DAB$l$rmime8ic)er.getCurrent5our@@ c$lend$r.setC$lend$r.234EB $l$rmime8ic)er.getCurrentinute@@ 2ntent m/2ntent = ne+ 2ntentAl$rmActivit/.t&isBAl$rm6eceiver.cl$ss@ 'ending2ntent = 8ending2ntent.get,ro$dc$stAl$rmActivit/.t&isB 0Bm/2ntentB 0@ $l$rm$n$ger.setAl$rm$n$ger.6CB c$lend$r.getime2nillis@B'ending2ntent@ else > $l$rm$n$ger.c$ncel'ending2ntent@ setAl$rmext""@ Log.d"/Activit/"B "Al$rm O"@

    'ulic void setAl$rmext7tring $l$rmext@ > $l$rmext;ie+.setext$l$rmext@

    3. !larm 9eceiver

    !larm9eceiver.java

    Alarm+eceiver is a W$)eul,ro$dc$s6eceiver, this is the one that receives the alarm tri""er on

    set time# From here 'e initiate i**erent actions to noti*y the user as per our choice# I have "iven

    three type o* noti*ications, *irst sho' a messa"e to user in the activity UI, secon play the alarm

  • 7/23/2019 Mobile Application Lab

    51/53

    rin"tone an thir sen an Anroi noti*ication messa"e# So this is the place to a enhancement

    *or i**erent types o* user noti*ications#

    '$c)$ge com.*$v$'$'ers.$ndroid$l$rmcloc)

    im'ort $ndroid.$''.Activit/im'ort $ndroid.content.Com'onent3$meim'ort $ndroid.content.Contextim'ort $ndroid.content.2ntentim'ort $ndroid.medi$.6ingtoneim'ort $ndroid.medi$.6ingtone$n$gerim'ort $ndroid.net.4riim'ort $ndroid.su''ort.vF.content.W$)eul,ro$dc$st6eceiver

    'ulic cl$ss Al$rm6eceiver extends W$)eul,ro$dc$st6eceiver >

    -Override 'ulic void on6eceivein$l Context contextB 2ntent intent@ > ((t&is +ill u'd$te t&e 42 +it& mess$ge

    Al$rmActivit/ inst = Al$rmActivit/.inst$nce@ inst.setAl$rmext"Al$rmG W$)e u'G W$)e u'G"@

    ((t&is +ill sound t&e $l$rm tone ((t&is +ill sound t&e $l$rm onceB i /ou +is& to ((r$ise $l$rm in loo' continuousl/ t&en use edi$8l$/er $ndsetLoo'ingtrue@ 4ri $l$rm4ri =6ingtone$n$ger.getDe$ult4ri6ingtone$n$ger.8E_ALA6@ i $l$rm4ri == null@ > $l$rm4ri =6ingtone$n$ger.getDe$ult4ri6ingtone$n$ger.8E_3O22CA2O3@ 6ingtone ringtone = 6ingtone$n$ger.get6ingtonecontextB $l$rm4ri@ ringtone.'l$/@

    ((t&is +ill send $ notiic$tion mess$ge Com'onent3$me com' = ne+ Com'onent3$mecontext.get8$c)$ge3$me@B Al$rm7ervice.cl$ss.get3$me@@ st$rtW$)eul7ervicecontextB intent.setCom'onentcom'@@@ set6esultCodeActivit/.6E74L_OK@

    ". !larm Foti'cation =essage

    !larm-ervice.java

    he receiver 'ill start the *ollo'in" 2ntent7erviceto sen a stanar noti*ication to the user#

    '$c)$ge com.*$v$'$'ers.$ndroid$l$rmcloc)

    im'ort $ndroid.$''.2ntent7ervice

  • 7/23/2019 Mobile Application Lab

    52/53

    im'ort $ndroid.$''.3otiic$tion$n$gerim'ort $ndroid.$''.8ending2ntentim'ort $ndroid.content.Contextim'ort $ndroid.content.2ntentim'ort $ndroid.su''ort.vF.$''.3otiic$tionCom'$tim'ort $ndroid.util.Log

    'ulic cl$ss Al$rm7ervice extends 2ntent7ervice > 'riv$te 3otiic$tion$n$ger $l$rm3otiic$tion$n$ger

    'ulic Al$rm7ervice@ > su'er"Al$rm7ervice"@

    -Override 'ulic void on5$ndle2ntent2ntent intent@ > send3otiic$tion"W$)e 4'G W$)e 4'G"@

    'riv$te void send3otiic$tion7tring msg@ >

    Log.d"Al$rm7ervice"B "8re'$ring to send notiic$tion...% " : msg@ $l$rm3otiic$tion$n$ger = 3otiic$tion$n$ger@ t&is .get7/stem7erviceContext.3O22CA2O3_7E6;2CE@

    8ending2ntent content2ntent = 8ending2ntent.getActivit/t&isB 0B ne+ 2ntentt&isB Al$rmActivit/.cl$ss@B 0@

    3otiic$tionCom'$t.,uilder $l$m3otiic$tion,uilder = ne+3otiic$tionCom'$t.,uildert&[email protected]"Al$rm"@.set7m$ll2con6.dr$+$le.ic_l$unc&er@ .set7t/lene+ 3otiic$tionCom'$t.,igext7t/[email protected]@@ .setContentextmsg@

    $l$m3otiic$tion,uilder.setContent2ntentcontent2ntent@ $l$rm3otiic$tion$n$ger.noti/1B $l$m3otiic$tion,uilder.uild@@ Log.d"Al$rm7ervice"B "3otiic$tion sent."@

  • 7/23/2019 Mobile Application Lab

    53/53