Professional Documents
Culture Documents
OOPS M6 Ktunotes - in - PDF
OOPS M6 Ktunotes - in - PDF
OOP
Module6
Appl
i
cat
ionSt
ruct
ure-
Andr
oidMani
fest
.xml
,uses-
per
missi
on&uses-
sdk
Ev
eryapppr
ojectmusthav
eanAndr
oidMani
fest
.xmlf
il
e(wi
thpr
eci
sel
ythatname)att
he
r
ootoft
hepr
ojectsour
ceset
.Themani
festf
il
edescr
ibesessent
iali
nfor
mat
ionabouty
ourappt
o
t
heAndr
oidbui
l
dtool
s,t
heAndr
oidoper
ati
ngsy
stem,
andGoogl
ePl
ay.
Amongmanyot
hert
hings,
themani
festf
il
eisr
equi
redt
odecl
aret
hef
oll
owi
ng:
Theapp'
spackagename,whi
chusual
l
ymat
chesy
ourcode'
snamespace.TheAndr
oidbui
l
d
t
ool
suset
hist
o det
ermi
net
hel
ocat
ionofcodeent
it
ieswhenbui
l
ding y
ourpr
oject
.When
packagi
ngt
heapp,t
hebui
l
dtool
srepl
acet
hisv
aluewi
tht
heappl
i
cat
ionI
Dfr
om t
heGr
adl
ebui
l
d
f
il
es,whi
chi
susedast
heuni
queappi
dent
if
ieront
hesy
stem andonGoogl
ePl
ay.Readmor
e
aboutt
hepackagenameandappI
D.
Thecomponent
soft
heapp,whi
chi
ncl
udeal
lact
ivi
ti
es,ser
vices,br
oadcastr
ecei
ver
s,and
cont
entpr
ovi
der
s.Eachcomponentmustdef
inebasi
cpr
oper
ti
essuchast
henameofi
tsKot
li
nor
Jav
acl
ass.I
tcanal
sodecl
arecapabi
l
iti
essuchaswhi
chdev
iceconf
igur
ati
onsi
tcanhandl
e,and
i
ntentf
il
ter
sthatdescr
ibehowt
hecomponentcanbest
art
ed.Readmor
eaboutappcomponent
s.
Theper
missi
onst
hatt
heappneedsi
nor
dert
oaccesspr
E S . ot
I N
ect
edpar
tsoft
hesy
stem orot
her
NOT
apps.I
tal
sodecl
aresanyper
missi
onst
hatot
herappsmusthav
eift
heywantt
oaccesscont
ent
KTU
f
rom t
hisapp.Readmor
eaboutper
missi
ons.
Thehar
dwar
eandsof
twar
efeat
urest
heappr
equi
res,whi
chaf
fect
swhi
chdev
icescani
nst
all
t
heappf
rom Googl
ePl
ay.Readmor
eaboutdev
icecompat
ibi
l
ity
.
Foreachappcomponentt
haty
oucr
eat
einy
ourapp,y
oumustdecl
areacor
respondi
ngXML
el
ementi
nthemani
festf
il
e:
<act
ivi
ty>f
oreachsubcl
assofAct
ivi
ty.
<ser
vice>f
oreachsubcl
assofSer
vice.
<r
ecei
ver
>foreachsubcl
assofBr
oadcast
Recei
ver
.
<pr
ovi
der
>foreachsubcl
assofCont
ent
Prov
ider
.
I
fyousubcl
assanyoft
hesecomponent
swi
thoutdecl
ari
ngi
tint
hemani
festf
il
e,t
hesy
stem
cannotst
arti
t.
Thenameofy
oursubcl
assmustbespeci
fi
edwi
tht
henameat
tr
ibut
e,usi
ngt
hef
ullpackage
desi
gnat
ion.Forexampl
e,anAct
ivi
tysubcl
asscanbedecl
aredasf
oll
ows:
<mani
fest.
..>
<appl
i
cat
ion.
..>
<act
ivi
tyandr
oid:
name="
com.
exampl
e.my
app.
Mai
nAct
ivi
ty".
..>
<act
ion> Addsanact
iont
oani
ntentf
il
ter
.
<act
ivi
ty> Decl
aresanact
ivi
tycomponent
.
<act
ivi
ty-
ali
as> Decl
aresanal
i
asf
oranact
ivi
ty.
<appl
i
cat
ion> Thedecl
arat
ionoft
E
heappl
i
S
cat
i. I
on. N
<cat
egor
y>
KTU
Addsacat
egor
NOT
ynamet
oani
ntentf
il
ter
.
<dat
a> Addsadat
aspeci
fi
cat
iont
oani
ntentf
il
ter
.
Speci
fi
es t
he subset
s ofapp dat
athatt
he par
entcont
entpr
ovi
derhas
<gr
ant
-ur
i-
per
missi
on>
per
missi
ont
oaccess.
Speci
fi
est
het
ypesofi
ntent
sthatanact
ivi
ty,ser
vice,orbr
oadcastr
ecei
ver
<i
ntent
-f
il
ter
>
canr
espondt
o.
<mani
fest
> Ther
ootel
ementoft
heAndr
oidMani
fest
.xml
fil
e.
Aname-
val
uepai
rforani
tem ofaddi
ti
onal
,ar
bit
rar
ydat
athatcanbesuppl
i
ed
<met
a-dat
a>
t
othepar
entcomponent
.
Def
inest
hepat
handr
equi
redper
missi
onsf
oraspeci
fi
csubsetofdat
awi
thi
n
<pat
h-per
missi
on>
acont
entpr
ovi
der
.
Decl
aresasecur
it
yper
missi
ont
hatcanbeusedt
oli
mitaccesst
ospeci
fi
c
<per
missi
on>
component
sorf
eat
uresoft
hisorot
herappl
i
cat
ions.
<per
missi
on-
group> Decl
aresanamef
oral
ogi
cal
groupi
ngofr
elat
edper
missi
ons.
E S . I N
NOT
TheXMLbel
owi
sasi
mpl
eexampl
eAndr
oidMani
fest
.xml
thatdecl
arest
woact
ivi
ti
esf
ort
heapp.
<?
xml
ver
<mani
f
sion="
est
1.
KTU
0"encodi
ng="
utf
-8"
?>
xml
ns:
andr
oid="
htt
p:/
/schemas.
andr
oid.
com/
apk/
res/
andr
oid"
andr
oid:
ver
sionCode="
1"
andr
oid:
ver
sionName="
1.0"
package="
com.
exampl
e.my
app"
>
<!
--Bewar
ethatt
hesev
aluesar
eov
err
iddenbyt
hebui
l
d.gr
adl
efi
l
e--
>
<uses-
sdkandr
oid:
minSdkVer
sion="
15"andr
oid:
tar
get
SdkVer
sion="
26"/
>
<appl
i
cat
ion
andr
oid:
all
owBackup="
tr
ue"
andr
oid:
i
con="
@mi
pmap/
ic_
launcher
"
andr
oid:
roundI
con="
@mi
pmap/
ic_
launcher
_round"
andr
oid:
l
abel
="@st
ri
ng/
app_
name"
andr
oid:
suppor
tsRt
l="
tr
ue"
andr
oid:
theme="
@st
yle/
AppTheme"
>
<!
--Thi
snamei
sresol
vedt
ocom.
exampl
e.my
app.
Mai
nAct
ivi
ty
KTU
andr
NOT
oid.
per
missi
on.
SEND_
SMS"
/>
</
mani
fest
>
Begi
nni
ngwi
thAndr
oid6.
0(APIl
evel23)
,theusercanappr
oveorr
ejectsomeappper
misi
onsat
r
unt
ime.Butnomat
terwhi
chAndr
oidv
ersi
ony
ourappsuppor
ts,
youmustdecl
areal
lper
missi
on
r
equest
swi
tha<uses-
per
missi
on>el
ementi
nthemani
fest
.Ift
heper
missi
oni
sgr
ant
ed,t
heapp
i
sabl
etouset
hepr
otect
edf
eat
ures.I
fnot
,it
sat
tempt
stoaccesst
hosef
eat
uresf
ail
.
Yourapp can al
so pr
otecti
ts own component
s wi
th per
missi
ons.I
tcan use anyoft
he
per
missi
onst
hatar
edef
inedbyAndr
oid,
asl
i
stedi
nandr
oid.
Mani
fest
.per
missi
on,
oraper
missi
on
t
hat
'
sdecl
aredi
nanot
herapp.Yourappcanal
sodef
inei
tsownper
missi
ons.Anewper
missi
oni
s
decl
aredwi
tht
he<per
missi
on>el
ement
.
<Uses-
sdk>
Eachsuccessi
vepl
atf
ormv
ersi
onof
tenaddsnew API
snotav
ail
abl
eint
hepr
evi
ousv
ersi
on.To
i
ndi
cat
ethemi
nimum v
ersi
onwi
thwhi
chy
ourappi
scompat
ibl
e,y
ourmani
festmusti
ncl
udet
he
<uses-
sdk>t
agandi
tsmi
nSdkVer
sionat
tri
but
e.
Howev
er,bewar
ethatat
tri
but
esi
nthe<uses-
sdk>el
ementar
eov
err
iddenbycor
respondi
ng
pr
oper
ti
es i
nthe bui
l
d.gr
adl
efi
l
e.So i
fyou'
re usi
ng Andr
oid St
udi
o,y
ou mustspeci
fyt
he
E S . I N
KTU NOT
2Rel
ati
veLay
out
Rel
ati
veLay
outi
sav
iewgr
oupt
hatdi
spl
ayschi
l
dvi
ewsi
nrel
ati
veposi
ti
ons.
3Tabl
eLay
out
Tabl
eLay
outi
sav
iewt
hatgr
oupsv
iewsi
ntor
owsandcol
umns.
7Gr
idVi
ew
E S . I N
Gr
idVi
Lay
ewi
saVi
outAt
tr
i
ewGr
but
es
oupt
hatdi
KTU
spl
aysi
temsi
NOT
nat
wo-
dimensi
onal
,scr
oll
abl
egr
id.
andr
oid:
i
d Thi
sist
heI
Dwhi
chuni
quel
yident
if
iest
hev
iew.
andr
oid:
l
ayout
_wi
dth Thi
sist
hewi
dthoft
hel
ayout
.
andr
oid:
l
ayout
_hei
ght Thi
sist
hehei
ghtoft
hel
ayout
andr
oid:
l
ayout
_mar
ginTop Thi
sist
heext
raspaceont
het
opsi
deoft
hel
ayout
.
andr
oid:
l
ayout
_mar
ginBot
tom Thi
sist
heext
raspaceont
hebot
tom si
deoft
hel
ayout
.
andr
oid:
l
ayout
_mar
ginLef
t Thi
sist
heext
raspaceont
hel
eftsi
deoft
hel
ayout
.
andr
oid:
l
ayout
_mar
ginRi
ght Thi
sist
heext
raspaceont
her
ightsi
deoft
hel
ayout
.
Andr
oidUICont
rol
s
1Text
View Thi
scont
rol
isusedt
odi
spl
ayt
extt
otheuser
.
2Edi
tText Edi
tTexti
sapr
e-def
inedsubcl
assofText
Viewt
hati
ncl
udesr
ichedi
ti
ng
capabi
l
iti
es.
3Aut
oCompl
eteText
View TheAut
oCompl
eteText
View i
sav
iew t
hati
ssi
mil
art
o Edi
tText
,
ex
ceptt
hati
tshowsal
i
stofcompl
eti
onsuggest
ionsaut
omat
ical
l
ywhi
l
etheuseri
sty
ping.
4But
ton Apush-
but
tont
hatcanbepr
essed,
orcl
i
cked,
byt
heusert
oper
for
m anact
ion.
5I
mageBut
ton Absol
uteLay
outenabl
esy
out
ospeci
fyt
heexactl
ocat
ionofi
tschi
l
dren.
9Radi
oGr
oup ARadi
oGr
oupi
susedt
ogr
oupt
oget
heroneormor
eRadi
oBut
tons.
10Pr
ogr
essBar ThePr
ogr
essBarv
iewpr
ovi
desv
isual
feedbackaboutsomeongoi
ng
t
asks,
suchaswheny
ouar
eper
for
mingat
aski
nthebackgr
ound.
Sampl
eCode
<Li
near
Lay
outxml
ns:
andr
oid="
htt
p:/
/schemas.
andr
oid.
com/
apk/
res/
andr
oid"
andr
oid:
l
ayout
_wi
dth="
fi
ll
_par
ent
"
andr
oid:
l
ayout
_hei
ght
="f
il
l_
par
ent
"
andr
oid:
ori
ent
ati
on="
ver
ti
cal
">
andr
oid:
text
="Thi
sisaText
View"/
>
<But
tonandr
oid:
i
d="
@+i
d/but
ton"
andr
oid:
l
ayout
_wi
dth="
wrap_
cont
ent
"
andr
oid:
l
ayout
_hei
ght
="wr
ap_
cont
ent
"
andr
oid:
text
="Thi
sisaBut
ton"/
>
E S . I N
Opt
i
Av
mi
oi
zi
ngl
ayout
s
dunnecessar
KTU
ynest
ing NOT
Av
oidusi
ngt
oomanyv
iews
Av
oiddeepnest
ingofl
ayout
s
Dr
awabl
eResour
ces
Gr
aphi
cst
hatcanbedr
awnt
oscr
eenorwhi
chcanbeappl
i
edt
oanot
herXML.Ar
epl
acedi
nthe
i
ntot
her
es/
drawabl
efol
der
.
Ther
ear
esev
eral
dif
fer
entt
ypesofdr
awabl
es:
Bi
tmapFi
l
e
Abi
tmapgr
aphi
cfi
l
e(.
png,
.j
pg,
or.
gif
).Cr
eat
esaBi
tmapDr
awabl
e.
Ni
ne-
Pat
chFi
l
e
APNGf
il
ewi
thst
ret
chabl
eregi
onst
oal
l
owi
mager
esi
zi
ngbasedoncont
ent(
.9.
png)
.Cr
eat
esa
Ni
nePat
chDr
awabl
e.
Lay
erLi
st
ADr
awabl
ethatmanagesanar
rayofot
herDr
awabl
es.Thesear
edr
awni
nar
rayor
der
,sot
he
el
ementwi
tht
hel
argesti
ndexi
sbedr
awnont
op.Cr
eat
esaLay
erDr
awabl
e.
St
ateLi
st
Desi
gnf
oref
fi
ci
entnet
wor
kaccess
A st
ylei
sacol
l
ect
ionofat
tri
but
est
hatspeci
fyt
heappear
ancef
orasi
ngl
eVi
ew.Ast
ylecan
speci
fyat
tr
ibut
essuchasf
ontcol
or,
fontsi
ze,
backgr
oundcol
or,
andmuchmor
e.
At
hemei
sat
ypeofst
ylet
hat
'
sappl
i
edt
oanent
ir
eapp,act
ivi
ty,orv
iew hi
erar
chy
,notj
ustan
i
ndi
vi
dual
view.
Tocr
eat
eanewst
yleort
heme,
openy
ourpr
oject
'
sres/
val
ues/
sty
l xmlf
es. il
e.Foreachst
yley
ouwant
t
ocr
eat
e,f
oll
owt
hesest
eps:
1. Adda<st
yle>el
ementwi
thanamet
hatuni
quel
yident
if
iest
hest
yle.
2. Addan<i
tem>el
ementf
oreachst
yleat
tri
but
eyouwantt
odef
ine.
Thenamei
neachi
tem speci
fi
esanat
tri
but
eyouwoul
dot
her
wiseuseasanXMLat
tr
ibut
einy
our
l
ayout
.Thev
aluei
nthe<i
tem>el
ementi
sthev
aluef
ort
hatat
tr
ibut
e.
Ex
ampl
e:
E S . I N
NOT
<?
xml
ver
sion="
1.0"encodi
ng="
utf
-8"
?>
KTU
<r
esour
ces>
<st
ylename="
GreenTex
t"par
ent
="Text
Appear
ance.
AppCompat
">
<i
tem name="
andr
oid:
text
Col
or"
>#00FF00</
it
em>
</
sty
le>
</
resour
ces>
Ex
tendandcust
omi
zeast
yle
Whencr
eat
ingy
ourownst
yles,
youshoul
dal
way
sext
endanexi
sti
ngst
ylef
rom t
hef
ramewor
kor
suppor
tli
brar
ysot
haty
oumai
ntai
ncompat
ibi
l
itywi
thpl
atf
orm UIst
yles.Toext
endast
yle,
speci
fyt
hest
yley
ouwantt
oext
endwi
tht
hepar
entat
tr
ibut
e.Youcant
henov
err
idet
hei
nher
it
ed
st
yleat
tri
but
esandaddnewones.
Forexampl
e,y
oucani
nher
itt
heAndr
oidpl
atf
orm'
sdef
aul
ttextappear
anceandmodi
fyi
tas
f
oll
ows:
<st
ylename="
GreenText
"par
ent
="@andr
oid:
sty
le/
Text
Appear
ance"
>
<i
tem name="
andr
oid:
text
Col
or"
>#00FF00</
it
em>
</
sty
le>
Appl
yast
yleasat
heme
Youcancr
eat
eat
hemet
hesamewayy
oucr
eat
est
yles.Thedi
ff
erencei
show y
ouappl
yit
:
KTU
ng
NOT
dermanagesaccesst
oacent
ralr
eposi
tor
yofdat
a.Youi
mpl
ementa
pr
ovi
derasoneormor
ecl
assesi
nanAndr
oidappl
i
cat
ion,
alongwi
thel
ement
sint
hemani
festf
il
e.
Oneofy
ourcl
assesi
mpl
ement
sasubcl
assCont
entPr
ovi
der
,whi
chi
sthei
nter
facebet
weeny
our
pr
ovi
derandot
herappl
i
cat
ions.Al
thoughcont
entpr
ovi
der
sar
emeantt
omakedat
aav
ail
abl
eto
ot
herappl
i
cat
ions,y
oumayofcour
sehav
eact
ivi
ti
esi
nyourappl
i
cat
iont
hatal
l
ow t
heusert
o
quer
yandmodi
fyt
hedat
amanagedbyy
ourpr
ovi
der
.
Fol
l
owt
hesest
epst
obui
l
dyourpr
ovi
der
:
Desi
gnt
her
awst
oragef
ory
ourdat
a.Acont
entpr
ovi
derof
fer
sdat
aint
woway
s:
o Fi
l
edat
a
o "
Str
uct
ured"dat
a
Def
ineaconcr
etei
mpl
ement
ati
onoft
heCont
entPr
ovi
dercl
assandi
tsr
equi
redmet
hods.
Thi
scl
assi
sthei
nter
facebet
weeny
ourdat
aandt
her
estoft
heAndr
oidsy
stem.
Def
inet
hepr
ovi
der
'saut
hor
it
yst
ri
ng,i
tscont
entURI
s,andcol
umnnames.I
fyouwantt
he
pr
ovi
der
'sappl
i
cat
iont
ohandl
eint
ent
s,al
sodef
inei
ntentact
ions,
ext
rasdat
a,andf
lags.Al
so
def
inet
heper
missi
onst
haty
ouwi
l
lrequi
ref
orappl
i
cat
ionst
hatwantt
oaccessy
ourdat
a.
Add ot
her opt
ional pi
eces, such as sampl
e dat
a or an i
mpl
ement
ati
on of
KTU
ed.
NOT
Ret
urnt
heMI
MEt
ypecor
respondi
ngt
oacont
entURI
.Thi
smet
hodi
sdescr
ibedi
nmor
edet
aili
n
t
hesect
ionI
mpl
ement
ingCont
entPr
ovi
derMI
METy
pes.
onCr
eat
e()
I
nit
ial
i
zey
ourpr
ovi
der
.TheAndr
oidsy
stem cal
l
sthi
smet
hodi
mmedi
atel
yaf
teri
tcr
eat
esy
our
pr
ovi
der
.Not
icet
haty
ourpr
ovi
deri
snotcr
eat
edunt
ilaCont
ent
Resol
verobj
ectt
ri
est
oaccessi
t.
SQl
i
tedat
abasei
sanopen-
sour
cel
i
ghtwei
ghtr
elat
ional
dat
abase.
SQLi
tedat
abasei
susedt
ost
oredat
ainst
ruct
uredf
ormat
.
Byst
ruct
ureddat
awemeanschema,
tabl
es"
rowsandcol
umns"
,indexes,
andsoon.
SQl
i
tedat
abasecomesembeddedwi
thi
nAndr
oidoper
ati
ngsy
stem.
SQLi
tedat
abasei
susedbyAndr
oidappl
i
cat
ionst
ost
oredat
ainpr
ivat
edat
abase.
Andr
oidpr
ovi
desast
andar
dAPIt
oint
eractwi
thSQLi
tedat
abasef
rom y
ourAndr
oidappl
i
cat
ion.
Usi
ngt
hest
andar
dAPIy
oucancr
eat
eadat
abaseandt
abl
esandper
for
m CRUD"
creat
e,r
ead,
updat
e,del
ete"oper
ati
ons.
Dat
abasecr
eat
edbyanappl
i
cat
ionwi
l
lbeaccessi
blebynamet
oanycl
assoft
hatappl
i
cat
ion,
butnotout
sidet
heappl
i
cat
ion.
E S . I N
NOT
}
KTU
St
ep4:
Upgr
adi
ngt
heDat
abase
Si
ncet
hedat
abasei
sbr
andnew,
wehav
enoupgr
adepol
i
cyweneedt
ofol
l
ow.Ther
efor
e,we'
l
ljustdr
op
t
het
abl
eandr
ecr
eat
eiti
fanupgr
ader
equesti
smade.
St
ep5:
Creat
ingt
heCont
entPr
ovi
derCl
ass
Nowt
haty
ourappl
i
cat
ionhasaf
unct
ional
dat
abase,
youcant
urny
ourat
tent
iont
oimpl
ement
ingacont
ent
pr
ovi
dert
oaccess,
expose,
andmanaget
hear
ti
cledat
ast
oredt
her
e.Begi
nbycr
eat
inganewcl
assnamed
Tut
li
stPr
ovi
derwhi
chext
endst
heCont
ent
Prov
idercl
ass.Gi
vei
tapr
ivat
ememberv
ari
abl
etohol
dan
i
nst
anceofaTut
List
Dat
abase.I
nst
ant
iat
ethedat
abasei
ntheonCr
eat
e()met
hod:
St
ep6:
Prepar
ingHel
perConst
ant
sandt
heMat
cher
Howev
er,
thi
sident
if
icat
iondoesn'
tact
ual
l
yhappenbymagi
c.I
nst
ead,
cont
entpr
ovi
dercl
assesgener
all
y
pr
ovi
desomepubl
i
cconst
ant
sthatcanbeusedbyappst
oident
if
ythedat
atheywantt
oquer
y.I
nsi
det
he
cont
entpr
ovi
der
,somehel
pisav
ail
abl
efordet
ermi
ningwhatki
ndofURIi
sbei
ngpassedi
n.
St
ep7:
Regi
ster
ingt
heCont
entPr
ovi
der
Li
keanAct
ivi
tycl
ass,
aCont
entPr
ovi
dermustbepr
oper
lyr
egi
ster
edi
ntheAndr
oidMani
festf
il
e.
St
ep8:
Updat
ingt
heLi
stVi
ew
Wi
tht
hecont
entpr
ovi
deri
mpl
ement
ati
oncompl
ete,
let
'
supdat
etheappl
i
cat
iont
ousei
t!Wi
thi
n
Tut
List
Fragmentcl
ass,
updat
etheonCr
eat
e()met
hodt
ouset
henewcont
entpr
ovi
der
E S . I N
KTU NOT