android material services

Upload: rayone9

Post on 06-Jul-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/18/2019 Android Material Services

    1/48

    Storage Methods:

    1. Shared Preferences

    2. SQLite Databse3. XML

    1). Shared Preferences :

    Interface for accessing and modifying reference data ret!rned by

    getSharedPreferences"String# int).

    SharedPreferences

    sf$getSharedPreferences"%myreferences%#&onte't. MODE_PRIVATE )(

    SharedPreferences.ditor  

    Interface !sed for modifying *a+!es in a SharedPreferences ob,ect.

    &reate a ne- ditor for these references# thro!gh -hich yo! can mae modifications to the data in the

     references and atomica++y commit those changes bac to the SharedPreferences ob,ect.

    SharedPreferences.ditor editor$sf.edit")(

     /ote : to get the data from shared refernces shared refrences ob,ect is eno!gh b!t to insert data or to

    modify data -e need to create Shared Preferences.ditor 0b,ect.

    he data is stored !sing ey#*a+!e airs yo! need ass a !ni!e ey for each *a+!e and yo! can

    insert oo+ean# 4+oat # Long # String # int data tye *a+!es.

      Sam+e Program on Shared Preferences :

    http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSharedPreferences(java.lang.String,%20int)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/SharedPreferences.Editor.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/SharedPreferences.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/SharedPreferences.Editor.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/SharedPreferences.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSharedPreferences(java.lang.String,%20int)

  • 8/18/2019 Android Material Services

    2/48

     main.xml

    56'm+ *ersion$"1.0"  encoding$"utf-8" 67

    58e+ati*eLayo!t 'm+ns:android$"http://schemas.and!d.c!m/ap#/es/and!d"   android:+ayo!t9-idth$"f$$_paent" 

      android:+ayo!t9height$"f$$_paent" 

      android:orientation$"%etca$"  7

      5e'tie-

      android:id$"&'d/te(tVe)1"   android:+ayo!t9-idth$")ap_c!ntent" 

      android:+ayo!t9height$")ap_c!ntent" 

      android:+ayo!t9a+ignParentLeft$"tue"   android:+ayo!t9a+ignParento$"tue"   android:+ayo!t9margino$"*8dp" 

      android:te't$ "Ente ,ame :"  

    android:te't;earance$"and!d:att/te(tAppeaanceMedum"  

  • 8/18/2019 Android Material Services

    3/48

      5!tton

      android:id$"&'d/utt!n1" 

      android:+ayo!t9-idth$")ap_c!ntent" 

      android:+ayo!t9height$")ap_c!ntent"   android:+ayo!t9a+ign8ight$"&'d/edtTe(t" 

      android:+ayo!t9be+o-$"&'d/edtTe(t" 

      android:+ayo!t9margino$"*dp"   android:on&+ic $"2a%e" 

      android:te't$ "2a%e"  

      SharedPreferences sf(

    SharedPreferences.ditor se(

    ?0*erride

      !b+ic *oid on&reate"!nd+e sa*edInstanceState) >  s!er.on&reate"sa*edInstanceState)(

      set&ontentie-"8.+ayo!t.main)(

     sf$getSharedPreferences"%myrefs%# &onte't.M0D9P8I;)(

     

    se$sf.edit")(

     !b+ic *oid Sa*e"ie- *)>

     dite't et1$"dite't)findie-yId"8.id.edite't1)(

      dite't et2$"dite't)findie-yId"8.id.edite't2)(

      se.!tString"%name%# et1.gete't").toString"))(  se.!tString"%ass%# et2.gete't").toString"))(

      se.commit")(

    @

  • 8/18/2019 Android Material Services

    4/48

      !b+ic *oid getDetai+s"ie- *)>

      String name$sf.getString"%name%#%here is no *a+!e -ith this ey%)(

      String ass$sf.getString"%ass%# %here is no *a+!e -ith this ey%)(

      oast.maee't"get;+ication&onte't")#%Aser /ame is :%BnameB% Pass is :%Bass#oast.L/C9L0/C ).sho-")(

    @

    @

    to e'+ore ersisted shared references se+ect DDMSEdataEdataEse+ect yo!r acage oen shared

     references yo! -i++ get an 'm+ -ith the references name.

    2). SQLite DataBase :

    SQLiteDatabase has methods to create# de+ete# e'ec!te SQL commands# and erform other

    common database management tass.

     /ote : Database names m!st be !ni!e -ithin an a+ication# not across a++ a+ications.

    oen0r&reateDatabase"String ath# SQLiteDatabase.&!rsor4actory factory)!i*a+ent to oenDatabase"ath# factory# &8;9I49/&SS;8F).

    Is !sed to create the SQLite 0b,ect if the data base is not a*ai+ab+e creates a ne- database if

    database is a+ready a*ai+ab+e then it oens the database .

     SQLiteDatabase dbo!en"r#reateDatabase$%mydb%ontext. MODE_PRIVATE & n'll((

    http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/database/sqlite/SQLiteDatabase.html#openOrCreateDatabase(java.lang.String,%20android.database.sqlite.SQLiteDatabase.CursorFactory)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/java/lang/String.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/database/sqlite/SQLiteDatabase.CursorFactory.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/database/sqlite/SQLiteDatabase.CursorFactory.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/database/sqlite/SQLiteDatabase.html#openOrCreateDatabase(java.lang.String,%20android.database.sqlite.SQLiteDatabase.CursorFactory)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/java/lang/String.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/database/sqlite/SQLiteDatabase.CursorFactory.html

  • 8/18/2019 Android Material Services

    5/48

    &!rsor : his interface ro*ides random readE-rite access to the res!+t set ret!rned by a database

    !ery.

    db.execSQL("create table employee(eid varchar2(20),ename varchar2(20),desig

    varchar2(20),dept varchar2(20));");

    his statement creates a ne- tab+e -ith em+oyee if tab+e is not there it -i++ create a ne- tab+e.

    If tab+e is a+ready a*ai+ab+e it -i++ thro!gh ! an e'cetion ! need to hand+e it.

    try>

     db.execSQL$%create table em!loyee$eid varchar)$)*(&ename varchar)$)*(&desigvarchar)$)*(&de!t varchar)$)*((+%(+

    ,catch$-xce!tion e(e.!rintStac/Trace$(+,

    Sam!le Program on SQLite Database :

    s+ite.'m+

    56'm+ *ersion$"1.0"  encoding$"utf-8" 6758e+ati*eLayo!t 'm+ns:android$"http://schemas.and!d.c!m/ap#/es/and!d"   android:+ayo!t9-idth$"match_paent" 

      android:+ayo!t9height$"match_paent"  7

  • 8/18/2019 Android Material Services

    6/48

      5e'tie-

      android:id$"&'d/te(tVe)1" 

      android:+ayo!t9-idth$")ap_c!ntent" 

      android:+ayo!t9height$")ap_c!ntent"   android:+ayo!t9a+ignParentLeft$"tue" 

      android:+ayo!t9a+ignParento$"tue" 

      android:+ayo!t9margino$"**dp"   android:te't$ "Emp$!5ee d :"  

    android:te't;earance$"and!d:att/te(tAppeaanceMedum"  

  • 8/18/2019 Android Material Services

    7/48

      5re!est4oc!s 

  • 8/18/2019 Android Material Services

    8/48

      android:+ayo!t9-idth$"f$$_paent" 

      android:+ayo!t9height$")ap_c!ntent" 

      android:+ayo!t9abo*e$"&'d/utt!n1" 

      android:+ayo!t9a+ignParentLeft$"tue"   android:on&+ic $"pdate" 

      android:te't$ "pdate"  

  • 8/18/2019 Android Material Services

    9/48

     s0lite.xml :

    56'm+ *ersion$"1.0"  encoding$"utf-8" 67

    58e+ati*eLayo!t 'm+ns:android$"http://schemas.and!d.c!m/ap#/es/and!d" 

      android:+ayo!t9-idth$"match_paent"   android:+ayo!t9height$"match_paent"  7

     

    5e'tie-  android:id$"&'d/te(tVe)1" 

      android:+ayo!t9-idth$")ap_c!ntent" 

      android:+ayo!t9height$")ap_c!ntent"   android:+ayo!t9a+ignParentLeft$"tue"   android:+ayo!t9a+ignParento$"tue" 

      android:+ayo!t9margino$"**dp" 

      android:te't$ "Emp$!5ee d :"  android:te't;earance$"and!d:att/te(tAppeaanceMedum"  

  • 8/18/2019 Android Material Services

    10/48

      5dite't 

    android:id$"&'d/edtTe(t" 

      android:+ayo!t9-idth$"100dp"   android:+ayo!t9height$")ap_c!ntent" 

      android:+ayo!t9a+ignLeft$"&'d/edtTe(t1" 

      android:+ayo!t9a+ignParent8ight$"tue"   android:+ayo!t9a+igno$"&'d/te(tVe)"  

  • 8/18/2019 Android Material Services

    11/48

      android:+ayo!t9a+ignParentLeft$"tue" 

      android:+ayo!t9be+o-$"&'d/utt!n*" 

      android:on&+ic $"4etDeta$s" 

      android:te't$ "4etDeta$s"  

    db.e'ecSQL"%create tab+e em+oyee"eid *archar2"2H)#ename *archar2"2H)#desig *archar2"2H)#det*archar2"2H))(%)(

     

  • 8/18/2019 Android Material Services

    12/48

      @catch"'cetion e)>

      e.rintStacrace")(

      @

     

    @

       !b+ic *oid Insert"ie- *)>

     

    dite't et1#et2#et3#et( 

    et1$"dite't)findie-yId"8.id.edite't1)(

      et2$"dite't)findie-yId"8.id.edite't2)(  et3$"dite't)findie-yId"8.id.edite't3)(

      et$"dite't)findie-yId"8.id.edite't)(

     

    &ontenta+!es c*$ne- &ontenta+!es")( 

    c*.!t"%eid%#et1.gete't").toString"))(

    c*.!t"%ename%# et2.gete't").toString"))(  c*.!t"%desig%# et3.gete't").toString"))(

      c*.!t"%det%# et.gete't").toString"))(

     db.insert"%em+oyee%#n!++#c*)(

     

    et1.sete't"%%)(

      et2.sete't"%%)(  et3.sete't"%%)(

      et.sete't"%%)(

    @

     !b+ic *oid Adate"ie- *)> 

    dite't et1#et2#et3#et(

     et1$"dite't)findie-yId"8.id.edite't1)(

      et2$"dite't)findie-yId"8.id.edite't2)(

      et3$"dite't)findie-yId"8.id.edite't3)(

      et$"dite't)findie-yId"8.id.edite't)( 

    &ontenta+!es c*$ne- &ontenta+!es")(

     c*.!t"%ename%# et2.gete't").toString"))(

      c*.!t"%desig%# et3.gete't").toString"))(

      c*.!t"%det%# et.gete't").toString"))( 

    db.!date"%em+oyee%# c*# %eid$6%# ne- StringJK>et1.gete't").toString")@)(

     

  • 8/18/2019 Android Material Services

    13/48

      et1.sete't"%%)(

      et2.sete't"%%)(

      et3.sete't"%%)(

      et.sete't"%%)(@

     

     !b+ic *oid De+ete"ie- *)>

      dite't et1(

     et1$"dite't)findie-yId"8.id.edite't1)(

     

    db.de+ete"%em+oyee%# %eid$6%# ne- StringJK>et1.gete't").toString")@)(

    et1.sete't"%%)(

    @

      !b+ic *oid getDetai+s"ie- *)>

     

    dite't et1( 

    et1$"dite't)findie-yId"8.id.edite't1)(

     

    &!rsor c$db.!ery"%em+oyee%# ne- StringJK>%eid%#%ename%#%desig%#%det%@# %eid$6%# ne-StringJK>et1.gete't").toString")@# n!++# n!++# n!++)(

    -hi+e "c.mo*eo/e't")) > 

    oast.maee't"get;+ication&onte't")# %id is :%Bc.getString"H)B%n name

    is :%Bc.getString"1)B%n Desig is :%Bc.getString"2)B%n Detis :%Bc.getString"3)#oast.L/C9L0/C).sho-")(

    @

    @@

  • 8/18/2019 Android Material Services

    14/48

      If yo! -ant e'+ore the db fi+e se+ect DDMSE data data se+ect yo!r acage inside acage ! -i++

    find a database fo+der and se+ect ! r db fi+e ! can !++ that one to !r system by se+ecting !++ a fi+e from

    the de*ice icon . SQLite  bro-ser is !sed to e'+ore yo!r s+ite dbfi+e .

     2sing 3ML :

    Fo! can ersist the data as a XML fi+e . he ad*antage if ! ersist the data in 'm+ ! can store

    the data into !r e'terna+ and interna+ storage and 'm+ interaab+e +ang!age . If yo! -ant share yo!r to

    some other techno+ogies !se XML format.

    o read and -rite the data into 'm+ fi+e -e need XML arsers.

    here are t-o tyes of arser are a*ai+ab+e

    1). N;XP " D0M "readE-rite) # S;X "8eadEon+y))

    2). N;X

    ;ndroid does not s!ort N;X.

    4or the abo*e ;cti*ity instead of ersisting the data into SQLite -e -i++ store the data in to XML

  • 8/18/2019 Android Material Services

    15/48

     4or/ing 5ith D"M :

    to r!n this a+ication ! need to add the be+o- ermission in the ;ndroidManifest.'m+ fi+e

     efore r!n this a+ication ! need to create a 'm+ fi+e in yo!r sdcard as the fo++o-ing str!ct!re

    mnt

  • 8/18/2019 Android Material Services

    16/48

    Doc!ment d$db.arse"f)(

    +ement e1$d.create+ement"%em+oyee%)(

    +ement e2$d.create+ement"%eid%)(+ement e3$d.create+ement"%ename%)(

    +ement e$d.create+ement"%desig%)(

    +ement eO$d.create+ement"%det%)(

    String eid#ename#desig#det(

    eid$et1.gete't").toString")(

    ename$et2.gete't").toString")(

    desig$et3.gete't").toString")(det$et.gete't").toString")(

     /ode n1$d.createe't/ode"eid)(

     /ode n2$d.createe't/ode"ename)( /ode n3$d.createe't/ode"desig)(

     /ode n$d.createe't/ode"det)(

    e2.aend&hi+d"n1)(

    e3.aend&hi+d"n2)(e.aend&hi+d"n3)(

    eO.aend&hi+d"n)(

    e1.aend&hi+d"e2)(e1.aend&hi+d"e3)(

    e1.aend&hi+d"e)(

    e1.aend&hi+d"eO)(

    d.getDoc!ment+ement").aend&hi+d"e1)(

    ransformer4actory tfr$ransformer4actory.ne-Instance")(

    ransformer tf$tfr.ne-ransformer")(

    D0MSo!rce ds$ne- D0MSo!rce"d)(

  • 8/18/2019 Android Material Services

    17/48

      et2.sete't"%%)(

      et3.sete't"%%)(

      et.sete't"%%)(

    @catch"'cetion e)>

      e.rintStacrace")(@

     

    @

     !b+ic *oid Adate"ie- *)>

     

     Doc!ment!i+der4actory dbf$Doc!ment!i+der4actory.ne-Instance")(

    Doc!ment!i+der db$dbf.ne-Doc!ment!i+der")(

    4i+e f$ne- 4i+e"n*ironment.get'terna+StorageDirectory")B%

  • 8/18/2019 Android Material Services

    18/48

     

     n.remo*e&hi+d"n+1.item",))(

    @

     @

     

    ransformer4actory tfr$ransformer4actory.ne-Instance")( 

    ransformer tf$tfr.ne-ransformer")(

     

  • 8/18/2019 Android Material Services

    19/48

      D0MSo!rce ds$ne- D0MSo!rce"d)(

  • 8/18/2019 Android Material Services

    20/48

      @

    oast.maee't"get;+ication&onte't")# msg#

    oast.L/C9L0/C).sho-")(

      @@catch"'cetion e)>

      e.rintStacrace")(

      @

    @

    @

    efore erforming de+ete oeration

    after de+ete oeration

  • 8/18/2019 Android Material Services

    21/48

     SA3 Parser :

    S;X Parser is the read on+y arser comare to D0M Parser reading the data !sing S;X

    Parser is easy and ha*ing mo*e ad*antages than D0M Parser .

     &ode to get the data !sing S;X Parser :

    add this method in the re*io!s e'am+e

    !'blic void getDataAsingS;X"ie- *)>

     

    try>

     4i+e f$ne5 4i+e"n*ironment. 4etE(tena$2t!a4eDect!5")B%

      oo+ean eid#ename#desig#det(

    ?0*erride

    !'blic void characters"charJK ch# int start# int +ength)

    thro5s S;X'cetion >

    oast.ma#eTe(t "get;+ication&onte't")# %m+oyee /ameis :%Bne5 String"ch# start# +ength)# oast. 7E,9T_2ORT ).sho-")(

    @

    i6 "desig)>

    oast.ma#eTe(t "get;+ication&onte't")# %m+oyee Desigis :%Bne5 String"ch# start# +ength)# oast. 7E,9T_2ORT ).sho-")(

    @

  • 8/18/2019 Android Material Services

    22/48

    i6 "det)>

    oast.ma#eTe(t "get;+ication&onte't")# %m+oyee Det

    is :%Bne5 String"ch# start# +ength)# oast. 7E,9T_2ORT ).sho-")(

    @

    @

    ?0*erride

    !'blic void end+ement"String !ri# String +oca+/ame# String /ame)

    thro5s S;X'cetion >

  • 8/18/2019 Android Material Services

    23/48

    i6 "/ame.e!a+s"%det%))>

    det$tr'e(

    @@

      @)(

    @catch"'cetion e)>  e.rintStacrace")(

    @

     @

     

    Android 4ith 7est6'l 4ebServices #omm'nication :

    ;ndroid SD inb!i+d is ha*ing s!orting +ibraries to comm!nicate -ith 8estf!+ ebSer*ices

    Sam!le code to interact 4ith 7est6'l 4ebServices :

     "My Intension is I -i++ ass t-o arameters to ser*er# get the resonse from the ser*er dis+ay theresonse message !sing oast)

      login.xml

    56'm+ *ersion$"1.0"  encoding$"utf-8" 6758e+ati*eLayo!t 'm+ns:android$"http://schemas.and!d.c!m/ap#/es/and!d" 

      android:+ayo!t9-idth$"match_paent" 

      android:+ayo!t9height$"match_paent"  7

      5e'tie-

      android:id$"&'d/te(tVe)1"   android:+ayo!t9-idth$")ap_c!ntent" 

      android:+ayo!t9height$")ap_c!ntent" 

      android:+ayo!t9a+ignParentLeft$"tue" 

  • 8/18/2019 Android Material Services

    24/48

      android:+ayo!t9a+ignParento$"tue" 

      android:+ayo!t9margino$"*dp" 

      android:te't$ "Ente ,ame"  

    android:te't;earance$"and!d:att/te(tAppeaanceMedum"  

  • 8/18/2019 Android Material Services

    25/48

    4ebServicesTest . 1ava

    !ac/age com.mahesh.'m+(

    im!ort =........................(

    !'blic class ebSer*icesest extends ;cti*ity>

    ?0*erride

    !rotected void on&reate"!nd+e sa*edInstanceState) >

  • 8/18/2019 Android Material Services

    26/48

     G get.addeader"%accet%#%image

  • 8/18/2019 Android Material Services

    27/48

    4or/ing 4ith 4eb9ie5:

    ; ie- that dis+ays -eb ages. his c+ass is the basis !on -hich yo! can ro++ yo!r o-n -eb

     bro-ser or sim+y dis+ay some on+ine content -ithin yo!r ;cti*ity. It !ses the ebit rendering

    engine to dis+ay -eb ages and inc+!des methods to na*igate for-ard and bac-ard thro!gh a history#

    Yoom in and o!t# erform te't searches and more.

    o enab+e the b!i+tEin Yoom# set ebSettings.set!i+tInZoom&ontro+s"boo+ean) "introd!ced in ;PI*ersion 3).

     /ote that# in order for yo!r ;cti*ity to access the Internet and +oad -eb ages in a ebie-# yo! m!st

    add the I,TER,ET  ermissions to yo!r ;ndroid Manifest fi+e:

    5!sesEermission android:name$%android.ermission.I/8/%

  • 8/18/2019 Android Material Services

    28/48

    4ebServicesTest.java

    !ac/age com.mahesh.'m+( 

    im!ort ..................(

    !'blic class ebSer*icesest extends ;cti*ity>

    ?0*erride

    !rotected void on&reate"!nd+e sa*edInstanceState) >7E_2PI,,ER)(

  • 8/18/2019 Android Material Services

    29/48

    -*.setebie-&+ient"ne5 ebie-&+ient")>

    ?0*erride

    !'blic void onPage4inished"ebie- *ie-# String !r+) >

  • 8/18/2019 Android Material Services

    30/48

    4i6i#on6ig'ration :

    ; c+ass reresenting a config!red iE4i net-or# inc+!ding the sec!rity config!ration.

    Sam!le #ode to 4or/ 4ith 4i6i :

     

    5i6i.xml:

    56'm+ *ersion$"1.0"  encoding$"utf-8" 67

    58e+ati*eLayo!t 'm+ns:android$"http://schemas.and!d.c!m/ap#/es/and!d"   android:+ayo!t9-idth$"match_paent" 

      android:+ayo!t9height$"match_paent"  7

     5!tton

      android:id$"&'d/t!44$e?utt!n1" 

      android:+ayo!t9-idth$")ap_c!ntent" 

      android:+ayo!t9height$")ap_c!ntent"   android:+ayo!t9a+ignParentLeft$"tue" 

      android:+ayo!t9a+ignParento$"tue" 

      android:+ayo!t9marginLeft$"113dp" 

      android:+ayo!t9margino$"dp"   android:on&+ic $"

  • 8/18/2019 Android Material Services

    31/48

      android:+ayo!t9a+ignParentLeft$"tue" 

      android:+ayo!t9be+o-$"&'d/t!44$e?utt!n1" 

      android:+ayo!t9marginLeft$"@dp" 

      android:+ayo!t9margino$"dp"   android:on&+ic $"4et

     b!tton.sete't"%ifi 0n%)(

    @e+se if"-Manager.getifiState")$$-Manager.I4I9S;9/;LD)>

     b!tton.sete't"%ifi 0ff%)(@

    @

     !b+ic *oid ifi"ie- *)>

    if"-Manager.getifiState")$$-Manager.I4I9S;9DIS;LD)>

    -Manager.setifinab+ed"tr!e)( b!tton.sete't"%ifi 0ff%)(

    @e+se if"-Manager.getifiState")$$-Manager.I4I9S;9/;LD)>

    -Manager.setifinab+ed"fa+se)( b!tton.sete't"%ifi 0n%)(

    @

    @

  • 8/18/2019 Android Material Services

    32/48

     

     !b+ic *oid getifiList"ie- *)>

    List5ifi&onfig!ration7 -ificonfig$-Manager.get&onfig!red/et-ors")(

    for"ifi&onfig!ration -ifi:-ificonfig)>

    oast.maee't"get;+ication&onte't")# % SSID : %B-ifi.SSID B% nSSID :%B-ifi.SSIDB%n Stat!s :%B-ifi.stat!sB%n

    Priority :%B-ifi.riority#oast.L/C9L0/C).sho-")(

    @@

    @

    ;oti6ication Manager :

    c+ass to notify the !ser of e*ents that haen. his is ho- yo! te++ the !ser that something has

    haened in the bacgro!nd. /otifications can tae different forms:

    • ; ersistent icon that goes in the stat!s bar and is accessib+e thro!gh the +a!ncher# "-hen the

    !ser se+ects it# a designated Intent can be +a!nched)#

    • !rning on or f+ashing LDs on the de*ice# or

    • ;+erting the !ser by f+ashing the bac+ight# +aying a so!nd# or *ibrating.

    ach of the notify methods taes an int id arameter. his id identifies this notification from yo!r a

    to the system# so that id sho!+d be !ni!e -ithin yo!r a. If yo! ca++ one of the notify methods -ith an

    id that is c!rrent+y acti*e and a ne- set of notification arameters# it -i++ be !dated. 4or e'am+e# ifyo! ass a ne- stat!s bar icon# the o+d icon in the stat!s bar -i++ be re+aced -ith the ne- one. his is

    a+so the same id yo! ass to the cance+"int) method to c+ear this notification.

    Fo! do not instantiate this c+ass direct+y( instead# retrie*e it thro!gh getSystemSer*ice"String).

    ;oti6ication :

     /otification; /otification ob,ect defines the detai+s of the notification message that is dis+ayed in the stat!s bar

    and %/otifications% -indo-# and any other a+ert settings# s!ch as so!nds and b+ining +ights.

    ; stat!s bar notification eues a++ of the fo++o-ing:• ;n icon for the stat!s bar

    • ; tit+e and e'anded message for the e'anded *ie- "!n+ess yo! define a c!stom e'anded*ie-)

    • ; PendingIntent# to be fired -hen the notification is se+ected

    0tiona+ settings for the stat!s bar notification inc+!de:

    • ; ticerEte't message for the stat!s bar

    • ;n a+ert so!nd

    http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/app/NotificationManager.html#cancel(int)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSystemService(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/app/Notification.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/guide/topics/ui/notifiers/notifications.html#CustomExpandedViewhttp://e/Android/android-sdk-windows-1.6_r1/docs/guide/topics/ui/notifiers/notifications.html#CustomExpandedViewhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/app/PendingIntent.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/app/NotificationManager.html#cancel(int)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSystemService(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/app/Notification.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/guide/topics/ui/notifiers/notifications.html#CustomExpandedViewhttp://e/Android/android-sdk-windows-1.6_r1/docs/guide/topics/ui/notifiers/notifications.html#CustomExpandedViewhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/app/PendingIntent.html

  • 8/18/2019 Android Material Services

    33/48

    • ; *ibrate setting

    • ; f+ashing LD setting

    9ibrator :

      &+ass that oerates the *ibrator on the de*ice.

    If yo!r rocess e'its# any *ibration yo! started -ith -i++ sto.

    Fo! do not instantiate this c+ass direct+y( instead# retrie*e it thro!gh getSystemSer*ice"String).

    Vi'rator vi'rator=(Vi'rator)getS&stemServi#e(ontet. VIBRATOR_SERVICE);

    *eed to add t+e ,o!!owing permission in t+e ndroidani,est.m!

     

     Develo! a sam!le code to dis!lay noti6ication and 9ibrate the device 5hen 5i6i is s5itch on or

    5i6i s5itch o66 6or the above a!!lication.

     acage com.mahesh.'m+(

    imort ,a*a.!ti+.List(

    imort =............................(

     !b+ic c+ass ifi'am+e e'tends ;cti*ity >

    ifiManager -Manager(

    !tton b!tton(

    http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSystemService(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSystemService(java.lang.String)

  • 8/18/2019 Android Material Services

    34/48

     /otificationManager nManager(

     /otification notification(

    ibrator *ibrator(

    ?0*erride

     rotected *oid on&reate"!nd+e sa*edInstanceState) >

    -Manager.setifinab+ed"fa+se)(

     b!tton.sete't"%ifi 0n%)(

    notification$ne- /otification"8.dra-ab+e.ic9+a!ncher# %ifi State

    &hanged%# System.c!rrentimeMi++is"))(

    notification.setLatest*entInfo"getase&onte't")# %ifi State

  • 8/18/2019 Android Material Services

    35/48

    &hanged%#%ifi Disab+ed%# getPendingIntent"))(

    nManager.notify"1# notification)(

    *ibrator.*ibrate"1HHH)(@

    @

      ri*ate PendingIntent getPendingIntent") >

    Intent i$ne- Intent"getase&onte't")# ifi'am+e.c+ass)(

    PendingIntent i$PendingIntent.get;cti*ity"getase&onte't")# H#i# H)(

    ret!rn i(

    @

     !b+ic *oid getifiList"ie- *)>

    List5ifi&onfig!ration7 -ificonfig$-Manager.get&onfig!red/et-ors")(

    for"ifi&onfig!ration -ifi:-ificonfig)>

    oast.maee't"get;+ication&onte't")# % SSID : %B-ifi.SSID B% nSSID :%B-ifi.SSIDB%n Stat!s :%B-ifi.stat!sB%n

    Priority :%B-ifi.riority#oast.L/C9L0/C).sho-")(

    @@

    @

      LocationManager :

    his c+ass ro*ides access to the system +ocation ser*ices. hese ser*ices a++o- a+ications to

    obtain eriodic !dates of the de*ice[s geograhica+ +ocation# or to fire an a+icationEsecified Intent 

    -hen the de*ice enters the ro'imity of a gi*en geograhica+ +ocation. Fo! do not instantiate this c+assdirect+y( instead# retrie*e it thro!gh &onte't.getSystemSer*ice"&onte't.L0&;I0/9S8I&).

    yo! need to add the fo++o-ing ermissions in ;ndroidManifest.'m+

     

       

     !b+ic *oid re!estLocationAdates "String  ro*ider# +ong minime# f+oat minDistance#

    LocationListener +istener)

    8egisters the c!rrent acti*ity to be notified eriodica++y by the named ro*ider. Periodica++y# thes!+ied LocationListener -i++ be ca++ed -ith the c!rrent Location or -ith stat!s !dates.

    http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Intent.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSystemService(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSystemService(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/java/lang/String.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/java/lang/String.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Intent.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/content/Context.html#getSystemService(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/java/lang/String.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.html

  • 8/18/2019 Android Material Services

    36/48

    It may tae a -hi+e to recei*e the most recent +ocation. If an immediate +ocation is re!ired#

    a+ications may !se the getLastno-nLocation"String) method.

    In case the ro*ider is disab+ed by the !ser# !dates -i++ sto# and the onPro*iderDisab+ed"String) 

    method -i++ be ca++ed. ;s soon as the ro*ider is enab+ed again# the onPro*idernab+ed"String) method-i++ be ca++ed and +ocation !dates -i++ start again.

    he fre!ency of notification may be contro++ed !sing the minime and minDistance arameters. If

    minime is greater than H# the LocationManager co!+d otentia++y rest for minime mi++iseconds

     bet-een +ocation !dates to conser*e o-er. If minDistance is greater than H# a +ocation -i++ on+y be broadcasted if the de*ice mo*es by minDistance meters. o obtain notifications as fre!ent+y as

     ossib+e# set both arameters to H.

    acgro!nd ser*ices sho!+d be caref!+ abo!t setting a s!fficient+y high minime so that the de*ice

    doesn[t cons!me too m!ch o-er by eeing the CPS or -ire+ess radios on a++ the time. In artic!+ar#*a+!es !nder THHHHms are not recommended.

    he ca++ing thread m!st be a Looer  thread s!ch as the main thread of the ca++ing ;cti*ity.

    Parameters

    !rovider the name of the ro*ider -ith -hich to register 

    minTime

    the minim!m time inter*a+ for notifications# in mi++iseconds. his fie+d is on+y !sed as a

    hint to conser*e o-er# and act!a+ time bet-een +ocation !dates may be greater or+esser than this *a+!e.

    minDistance the minim!m distance inter*a+ for notifications# in meters

    listenera >\+in LocationListener@ -hose onLocation&hanged"Location) method -i++ be ca++ed

    for each +ocation !date

     Sam!le #ode to 4or/ 5ith LocationBasedServices :

    pac%age #om.ma+es+.m!;

    import ..............................;

    http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.html#onProviderDisabled(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.html#onProviderEnabled(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/os/Looper.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.html#onLocationChanged(android.location.Location)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.html#onProviderDisabled(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.html#onProviderEnabled(java.lang.String)http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/os/Looper.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/location/LocationListener.html#onLocationChanged(android.location.Location)

  • 8/18/2019 Android Material Services

    37/48

    p$blic class $o#ationest extends #tivit&0

    $o#ationanager !anager;

    12verride

    protected void onreate(3und!e saved%nstan#eState) 0

    // &'& uto-generated met+od stu's$per.onreate(saved%nstan#eState);

    setontentView(4.!a&out. o!aion);

    !anager=($o#ationanager)getS&stemServi#e(ontet. LOCATION_SERVICE);

    !anager.re5uest$o#ationUpdates($o#ationanager. G#S_#ROVI$ER 6 78886 76

    ne $o#ation$istener() 0

    12verride

    p$blic void onStatus+anged(String arg86 int arg76 3und!e arg9) 0

    // &'& uto-generated met+od stu'

    12verride

    p$blic void onProviderna'!ed(String arg8) 0

    // &'& uto-generated met+od stu'

    12verride

    p$blic void onProviderisa'!ed(String arg8) 0

    // &'& uto-generated met+od stu'

    12verridep$blic void on$o#ation+anged($o#ation !) 0

    // &'& uto-generated met+od stu'

    oast.ma%eTe&(getpp!i#ationontet()6 $atitude va!ue

    is :!.get$atitude()$ogitude va!ue is :!.get$ongitude()6 oast.LENGT'_S'ORT ).s+ow();

     

    );

    p$blic void get$o#ation(View v)0

    $o#ation !=!anager.get$ast?nown$o#ation($o#ationanager.G#S_#ROVI$ER);

    oast.ma%eTe&(getpp!i#ationontet()6 $atitude va!ue is :!.get$atitude()

    $ogitude va!ue is :!.get$ongitude()6 oast.LENGT'_S'ORT ).s+ow();

  • 8/18/2019 Android Material Services

    38/48

    List#ctivity

    n a#tivit& t+at disp!a&s a !ist o, items '& 'inding to a data sour#e su#+ as an arra& or ursor6

    and eposes event +and!ers w+en t+e user se!e#ts an item.

    List;cti*ity hosts a Listie- ob,ect that can be bo!nd to different data so!rces# tyica++y either anarray or a &!rsor ho+ding !ery res!+ts. inding# screen +ayo!t# and ro- +ayo!t are disc!ssed in the

    fo++o-ing sections.

    Screen Layo't 

    List;cti*ity has a defa!+t +ayo!t that consists of a sing+e# f!++Escreen +ist in the center of the screen.o-e*er# if yo! desire# yo! can c!stomiYe the screen +ayo!t by setting yo!r o-n *ie- +ayo!t -ith

    set&ontentie-") in on&reate"). o do this# yo!r o-n *ie- MAS contain a Listie- ob,ect -ith the

    id %?android:id 

    Base Ada!ter :

    &ommon base c+ass of common im+ementation for an ;dater  that can be !sed in both

    Listie- "by im+ementing the secia+iYed List;dater  interface@ and Sinner  "by im+ementing the

    secia+iYed Sinner;dater  interface.

    http://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/ListView.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/R.id.html#listhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/Adapter.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/Adapter.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/ListView.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/ListAdapter.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/Spinner.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/Spinner.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/SpinnerAdapter.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/ListView.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/R.id.html#listhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/Adapter.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/ListView.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/ListAdapter.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/Spinner.htmlhttp://e/Android/android-sdk-windows-1.6_r1/docs/reference/android/widget/SpinnerAdapter.html

  • 8/18/2019 Android Material Services

    39/48

     Sample !rogram to display image names in S'*#+' $sing List#ctivity

     

    !ac/age com.mahesh.'m+(

    im!ort ,a*a.io.4i+e(

    im!ort =..................(

    !'blic class List;cti*ityest extends List;cti*ity>

    ?0*erride

    !rotected void on&reate"!nd+e sa*edInstanceState) >

  • 8/18/2019 Android Material Services

    40/48

    @else>

    oast.ma#eTe(t "get;+ication&onte't")# %here is no fi+e -ith the gi*en

     ath%#oast. 7E,9T_7O,9).sho-")(

    @@

     @

     Sam!le !rogram on creating o5n #'stom9ie5 Ada!ter and dis!lay image & image name and

    image si

  • 8/18/2019 Android Material Services

    41/48

  • 8/18/2019 Android Material Services

    42/48

      "i!e ,=new "i!e(pat+);

      ,i!es=,.!ist();

     

    pu'!i# int getount() 0// 22 uto-generated met+od stu'

    return ,i!es.!engt+;

    pu'!i# 2'Ee#t get%tem(int position) 0

    // 22 uto-generated met+od stu'

    return position;

    pu'!i# !ong get%tem%d(int position) 0// 22 uto-generated met+od stu'

    return position;

    pu'!i# View getView(int position6 View view6 ViewFroup viewDgroup) 0

    // 22 uto-generated met+od stu'

    view=in,!ater.in,!ate(4.!a&out.main6nu!!);

    etView tv7=(etView) view.,indView3&%d(4.id.tetView7);

    etView tv9=(etView) view.,indView3&%d(4.id.tetView9);

    %mageView iv7=(%mageView)view.,indView3&%d(4.id.imageView7);

     

    tv7.setet(,i!esBpositionC.toString());

    "i!e ,=new "i!e(pat+/,i!esBpositionC);

    tv9.setet(,.!engt+()/789G@');

    iv7.set%mageU4%(Uri.,rom"i!e(,));

    return view;

     

  • 8/18/2019 Android Material Services

    43/48

  • 8/18/2019 Android Material Services

    44/48

    main.xml

     

     

  • 8/18/2019 Android Material Services

    45/48

    alleryestx#ctivity.ava 

    pa#@age #om.ma+es+.ga!!er&;

    import ...................................;

    pu'!i# #!ass Fa!!er&est#tivit& etends #tivit& imp!ements 2n%temSe!e#ted$istener 0

    rra&$ist imagesDnames=new rra&$ist();

    /AA a!!ed w+en t+e a#tivit& is ,irst #reated. A/

      12verride

      pu'!i# void onreate(3und!e saved%nstan#eState) 0

    super.onreate(saved%nstan#eState);

      setontentView(4.!a&out.ga!!er&); 

    Fa!!er& g=(Fa!!er&),indView3&%d(4.id.ga!!er&7);

     

    g.setdapter(new &dapter(t+is));

    g.set2n%temSe!e#ted$istener(t+is);

    pu'!i# void on%temSe!e#ted(dapterView adview6 View view6 int arg96!ong argI) 0

    +e#@3o #'7=(+e#@3o),indView3&%d(4.id.#+e#@3o7);

    i,(#'7.is+e#@ed())0

    imagesDnames.add(#'7.getet().toString());

    oast.ma@eet(getpp!i#ationontet()6#'7.getet()6oast.$*FJD$2*F).s+ow();

    pu'!i# void on*ot+ingSe!e#ted(dapterView arg8) 0

    // 22 uto-generated met+od stu'

    oast.ma@eet(getpp!i#ationontet()6

    imagesDnames.siKe()6oast.$*FJD$2*F).s+ow();

  • 8/18/2019 Android Material Services

    46/48

     MyAda!ter.java :

     acage com.mahesh.ga++ery(

    imort =..................(  !b+ic c+ass My;dater e'tends ase;dater>

    Ca++eryest';cti*ity gta(

    Layo!tInf+ater inf+ater(

    String ath$n*ironment.get'terna+StorageDirectory")B%

    ret!rn osition(@

     !b+ic +ong getItemId"int osition) >

    ret!rn osition(

    @

     !b+ic ie- getie-"int osition# ie- *ie-# ie-Cro! arg2) >

    *ie-$inf+ater.inf+ate"8.+ayo!t.main# n!++)(

  • 8/18/2019 Android Material Services

    47/48

    Imageie- i*1$"Imageie-)*ie-.findie-yId"8.id.imageie-1)(

    &heco' cb1$"&heco')*ie-.findie-yId"8.id.checo'1)(

    cb1.sete't"imagesJositionK.toString"))(

    4i+e f$ne- 4i+e"athB%

  • 8/18/2019 Android Material Services

    48/48

    setDataSo!rce >Id+e@

    >Initia+iYed#

    Preared# Started#

    Pa!sed# Stoed#

    P+aybac&om+eted# rror@

    S!ccessf!+ in*oe of this method in a *a+id statetransfers the ob,ect to the Inta$Bed  state. &a++ing

    this method in an in*a+id state thro-s an

    I++ega+State'cetion.

    seto+!me

    >Id+e# Initia+iYed#Stoed# Preared#

    Started# Pa!sed#

    P+aybac&om+eted@

    >rror@ S!ccessf!+ in*oe of this method does not changethe state.

    start

    >Preared# Started#

    Pa!sed#P+aybac&om+ete

    d@

    >Id+e# Initia+iYed#Stoed# rror@

    S!ccessf!+ in*oe of this method in a *a+id state

    transfers the ob,ect to the 2tated  state. &a++ingthis method in an in*a+id state transfers the ob,ect

    to the E!  state.

    sto>Preared# Started#Stoed# Pa!sed#

    P+aybac&om+eted@

    >Id+e# Initia+iYed#

    rror@

    S!ccessf!+ in*oe of this method in a *a+id statetransfers the ob,ect to the 2t!pped  state. &a++ingthis method in an in*a+id state transfers the ob,ect

    to the E!  state.