0% found this document useful (0 votes)
22 views26 pages

Unit Ii

The document provides an overview of Android application design essentials, including the anatomy of Android applications and their components such as Activities, Services, Broadcast Receivers, and Content Providers. It explains the distinct purposes and lifecycle of each component, highlighting their roles in user interaction and background processing. Additionally, it touches on the Android architecture and essential tools required for application development.

Uploaded by

chakrapanimca12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views26 pages

Unit Ii

The document provides an overview of Android application design essentials, including the anatomy of Android applications and their components such as Activities, Services, Broadcast Receivers, and Content Providers. It explains the distinct purposes and lifecycle of each component, highlighting their roles in user interaction and background processing. Additionally, it touches on the Android architecture and essential tools required for application development.

Uploaded by

chakrapanimca12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

UNI T-I

I
Andr oi
dAppl i
cati
onDesi gnEssent i
als
Under standingAnat omyofAndr oidAppl i
cati
on,Andr oidter minol
ogies,Creati
ngUserInterfaceswit
hbasic
views–Appl icati
onCont ext
,Activ
iti
es,Services,Int
ent s,l
inkingactivi
ti
eswi thInt
ent
s,ReceivingandBroad
castingIntents,AndroidManifestFil
eandi tscommonset tings,Usi
ngI ntent
Fil
ter,
Per
mi ssi
ons.
Anat omyofAndr oi
dApplicati
on(OR)Component sofanAndr oidApplicati
on(OR)Buildi
ngBl ocksofan
Andr oi
dappl icati
on:
Appcomponent saretheessenti
albuil
dingblocksofanAndr oidapp.Eachcomponentisanent rypoi
nt
throughwhi chthesy st
em orausercanent ery ourapp.Somecomponent sdependonothers.

Ther
earef
ourtypesofappcomponent
s:
 Act
ivi
ti
es

 Ser
vices

 Br
oadcastr
ecei
ver
s

 Cont
entpr
ovi
der
s
Eachty
peserv
esadi
sti
nctpur
poseandhasadi
sti
nctl
i
fecy
clet
hatdef
ineshowacomponenti
scr
eat
edand
dest
royed.

1.Acti
vit
ies:
Anactivi
tyi
stheentrypointfori
nteract
ingwiththeuser.Itr
epresentsasingl
escr eenwithauserint
erf
ace.For
example,anemailappmighthav eoneact i
vit
ythatshowsal i
stofnewemai l
s,anotheracti
vi
tytocomposean
email
,andanotheracti
vit
yforreadingemai l
s.Alt
hought heacti
vit
iesworktogethertoform acohesi
veuser
exper
ienceint
heemai lapp,eachonei sindependentoftheothers.

Adiff
erentappcanst
artanyoneoftheseact
ivi
ti
esi
ftheemail
appall
owsit.Forexampl
e,acamer
aappmi
ght
st
arttheacti
vi
tyi
ntheemailappforcomposi
nganewemai l
tolett
heusershareapict
ure.

Anact
ivi
tyf
aci
l
itat
est
hef
oll
owi
ngkeyi
nter
act
ionsbet
weensy
stem andapp:

 Keepingt
rackofwhattheusercur
rentl
ycar
esabout
—whati
son-
scr
een—sot
hatt
hesy
stem keeps
runni
ngtheprocesst
hatishost
ingtheact
ivi
ty.

 Knowingwhichpr
eviousl
yusedprocessescont
ainst
oppedacti
vi
ti
est
heusermi
ghtr
etur
ntoand
pr
ior
it
izi
ngthoseprocessesmor
ehi ghl
ytokeepthem av
ail
abl
e.

 Hel
pingtheapphandl
ehav
ingi
tspr
ocesski
l
ledsot
heusercanr
etur
ntoact
ivi
ti
eswi
tht
hei
rpr
evi
ous
st
aterest
ored.

 Prov
idi
ngawayf orappst
oimpl
ementuserf
lowsbet
weeneachot
her
,andf
ort
hesy
stem t
o
coor
dinat
ethesefl
ows.
Synt
ax:
publ
iccl
assMai
nAct
ivi
tyext
endsAct
ivi
ty

2.Ser
vices:
Aservi
ceisageneral
-purposeent
rypointforkeepi
nganapprunni
ngint
hebackgr
oundf
orall
kindsofreasons.
I
tisacomponentthatrunsinthebackgroundtoperfor
mlong-
runni
ngoper
ati
onsort
operf
orm workf
or
1 MADMat
eri
al(
VL) MTDC:
PALAMANER
r
emot
epr
ocesses.Aser
vicedoesnotpr
ovi
deauseri
nter
face.

Forexample,aser
vicemightplaymusicint
hebackgroundwhi l
etheuserisi
nadiff
erentapp,ori
tmightf
etch
dataoverthenet
wor kwi
thoutblocki
nguseri
nter
act
ionwi t
hanact i
vit
y.Anot
hercomponent,suchasan
act
ivi
ty,canst
artt
heserviceandleti
trunorbi
ndtoittointer
actwithit
.

Ther
ear
etwot
ypesofser
vicest
hatt
ell
thesy
stem howt
omanageanapp:

 St
art
edser
vicesand

 Boundser
vices.

Star
tedserv
icest
ellt
hesy st
em tokeepthem runningunti
lthei
rwor kiscomplet
ed.Thi
smightbet osync
somedat ai
nthebackgroundorplaymusicevenaft ert
heuserleavestheapp.Synci
ngdat
ai nthebackgr
ound
orpl
ayingmusicr
epresentdif
fer
enttypesofstart
edser vi
ces,whichthesyst
em handl
esdi
fferent
ly:

 Musi
cpl
aybacki
ssomet
hingt
heuseri
sdi
rect
lyawar
eof
,andt
heappcommuni
cat
est
hist
othe
system byindi
cati
ngthatitwant
stobei nthefor
egr
ound,withanot
ifi
cat
iontotel
ltheusert
hati
tis
running.I
nthiscase,t
hesy st
em pr
iori
ti
zeskeepi
ngthatser
vice'
spr
ocessrunni
ng,becauset
heuser
hasabadexper ienceifi
tgoesaway .
 Ar
egul
arbackgr
oundser
vicei
snotsomet
hingt
heuseri
sdi
rect
lyawar
eof
,sot
hesy
stem hasmor
e
fr
eedom i
nmanagingi
tspr
ocess.I
tmightl
eti
tbekil
l
ed,restar
ti
ngtheser
vicesomet
imel
ater
,ifi
t
needsRAM f
ort
hingst
hatareofmoreimmedi
ateconcer
nt otheuser
.
Boundser vi
cesrunbecausesomeot herapp( orthesy st
em)hassaidt hati
twant st
omakeuseoft heserv
ice.
Aboundser viceprov
idesanAPIt oanotherpr ocess,andthesystem knowst her
eisadependencybetween
theseprocesses.SoifprocessAisboundt oaser vi
ceinprocessB,thesystem knowsthati
tneedstokeep
processBandi tsser
v i
cerunningforA.Further,i
fprocessAi ssomethingtheusercaresabout
,theni
tknows
totreatpr
ocessBassomet hingtheuseralsocar esabout.

Becauseoft heirf
lexibil
it
y,serv i
cesareusef ulbuil
dingblocksforall ki
ndsofhi gher
-l
evel syst
em
concepts.Liv ewallpapers, notif
icat
ionl i
steners,screensav er
s,inputmet hods,accessibil
it
yservices,
andmanyot hercor esy stem feat ur
esar eal lbuil
tasservicesthatapplicati
onsi mpl
ementandt he
system bindst owhent heyr un.
3.Br
oadcastreceiver s:
Abr oadcastr ecei
veri sacomponentt hatletst hesystem deli
verev ent
st otheappout sideofar egular
userflowsot heappcanr espondt osy stem- widebroadcastannouncement s.Becausebr oadcast
receiv
ersar eanotherwel l
-definedentryint otheapp, thesystem candel i
verbroadcastsev entoapps
thataren'
tcur rent
lyrunning.

So,forexample,anappcanschedul eanal
armtopostanotif
icat
iont
otel
ltheuseraboutanupcoming
event.Becausethealar
misdeliver
edtoaBroadcastRecei
verint
heapp,t
herei
snoneedf ortheappto
remainrunningunti
ltheal
arm goesoff.

4.Cont
entprovider
s:
Acont entpr
ov i
dermanagesashar edsetofappdatat hatyoucanstor
ei nthefi
l
esy st
em,i
naSQLite
database,ontheweb, oronanyotherpersi
stentst
oragelocati
onthatyourappcanaccess.Thr
ough
thecontentprovider
,otherappscanqueryormodifythedata,i
fthecontentprovi
derpermi
tsi
t.

Forexample,t
heAndroidsyst
em provi
desacontentpr
ov i
derthatmanagestheuser'scont
act
i
nformati
on.Anyappwi t
htheproperper
missi
onscanquer ythecont
entprovider
,suchas
usi
ngContactsCont
ract.
Data,
toreadandwrit
einfor
mationaboutaparti
cularperson.
2 MADMat eri
al(VL) MTDC: PALAMANER
BASI
CTERMI
NOLOGI
ESOFANDROI
D
Androidisan‘
Open- sour
ce’operat
ingsy stem usedt odevelopanappl icati
onformobi l
edevi
ces.ItisaLinux
basedoperati
ngsy stem.I
nit
iall
y,i
twast enuredby‘ Openal l
iancehandset ’andin2007itwasoccupi edby
google.Thesourcecodepubl i
shedbyGoogl ei sundert heApacheLi censev er
sion2.0.Andr
oidsmar tphones
areusedbymi l
li
onsofpeopl eworldwi
de.Underr esearches,resear
cher ssaythataround3mi l
li
onpeopl eare
usinganandroi
dsmar t
phone.Theandr oidapplicati
oncompl et
elyt
ransf or
mst hewayt ocommuni cateand
i
nteractwit
heachot hereveninthemilesofdi stance.

Ar
chi
tect
ureofAndr
oid

Theandroi
darchi
tect
urei
st hecombinat
ionoff
ourl
ayer
s.Howev
er,
onel
ayeri
spar
ti
ti
onedi
ntot
wosect
ions
so,i
tconsi
stsoff
ivesect
ionsinal
l.
 LI
NUXKERNEL:
I
tisthelowestl ayerofandr oidarchit
ectur
e.Itser
vesastheabst r
actionbetweenthehardwarelevel
of
thedevi
ceandcont ainsal lt
her equi
redhardwaredri
vers.
 LIBRARIES:
I
tholdslibrari
esforst oringt hedataalongthelibr
ari
esusesforinternetsecur
it
ypurposes.
 ANDROI DRUNTI ME:
Thissectionhast helibrar i
eswhi chenablethedevel
opertowr i
tethecodeofandroidapplicat
ionusi
ng
anystandar dprogrammi ngl anguage.
 APPLICATI ONFRAMEWORK:
I
tisthethi r
dlayer.Itserv estheser v
icestotheappli
cati
onlayerintheform ofj
avaclasses.
 Appli
cation:
I
tisthefor emostl ay erthati susedt oi
nstall
theappli
cati
onsinthedev i
ces.

Essent
ialTool
sforandr
oidappl
icat
iondev
elopment

Themosti
mpor
tantt
ool
srequi
redf
orappl
i
cat
iondev
elopmentar
e:
 JDK:Jav
aDev
elopmentki
tthati
sthecombi
nat
ionoft
wopr
emi
ert
ool
sJAVAVI
RTUALMACHI
NEand
JAVARUNTI MEENVI RONMENT.I thel psincompi l
ingandr unni ngthej avaprogr am.
 ANDROI DSTUDI O:Thepr imar ygoal tointroducet heandr oidst udioistodev elopt heandroid
appl i
cat i
onsi nt hemostst abletool .Atfir
standr oidapplicati
onswer edev elopedi neclipsebut,app
dev elopersf acemul tiplei ssuesi necl i
pse.Theni n2007, googlebr i
ngst heandr oidstudiothatisused
particularlyintroducedf orandr oid.
Ter
minologiesCor relatedt oAndr oid
 XMLf i
le
Thepr eemi nentf il
eisusedf orthest ructureofanandr oidproject .I
thascompl et einf
ormat i
onaboutall
thecomponent sandpackages.I tinit
iali
zest heAPIt hatisfur t
herusedbyanappl icat
ion.
 Lay out
Itproper lyalignedt hev iewsont hescr een.
 Ac ti
vity
Act i
vityisaUseri nt
er facescr eent hroughwhi chtheuseri nteracts.User shav ear i
ghttoplacetheUI
element sinanywayaccor dingtot heUser schoi ce.
 Emul ator
Theemul atorist hev irtual devicesmar tphonepr ovidedwi thanandr oidstudio.Youcanr uny our
createdappl icationont heemul atorandt esti t
sUIandf unctionaccor dingtot heneeds.
 I ntent
Itactsasacommuni cat ingobj ect.Youcanest abli
shacommuni cati
onbet weent woormor ethantwo
component sasser vices, broadcastr eceivers.Itisusedt ost artandendt heact i
v i
tyandser vi
ces
component s.
 Se rvi
ces
3 MADMat
eri
al(
VL) MTDC:
PALAMANER
Iti
susedtorunt heprocesseveninthebackground.Ther
eisnodef
inedUIf
orser
vice.Anycomponent
canstartt
heserviceandendt heserv
ices.Youcaneasil
yswit
chbet
weentheappl
icati
onseveni
fthe
servi
cesarerunningthebackground.
 ContentProvi
der
Iti
mplementedint woway s:

1.Youcanuseimpl
ementt
heexi
sti
ngcont
entpr
ovi
deri
nyourappli
cati
on.
2.However
,youcanal
socr
eat
eanewcontentpr
ovi
dert
hatwil
lprovi
deorshar
ethedat
awi
thot
her
appl
i
cati
ons.

Cr
eat
ingUserI
nterf
aceswi
thbasi
cvi
ews

View: Ablockoft hescr eenwhi chisr esponsi blef ortheUIoft heappl icat i
oni scalledaVi ew.Anandr oidapp
UIconsi st
sofv iewsandVi ewGr oups.Vi ewr eferst oandr oid.view.Vi ew cl assofandr oid,wi t
ht hehelpof
thi
scl assalltheot herGUIel ement saredr awn.I tisresponsi bl
efordr awi ngandev enthandl i
ngi nandroi
d
applicat
ions.
ViewGr oup:AVi ewGr oupholdst ogetherotherVi ewsorev enVi ewGr oups.I t’
sessent ial
l
yawayt ocombi ne
diff
erentViews,allowingformor ecompl exandor ganizedlay outsiny ourapp.AVi ewi sabasi cUIelement
thatismeantt obedi splayedont hescr een,li
keabut tonorat extfi
eld, aVi ewGr oupdoesn’ tdi spl
ayany
contentofitsownbutser vesasacont ai
nertoor ganizeandmanageot herVi ews.
ViewGr oupspr ovideast r
uctural f
ramewor kt hathelpsi nor gani zi
ngv ari
ousVi ewswi thina
screen.Bynest i
ngVi ewswi thi
naVi ewGr oup, dev eloperscancr eat
ehi er archicalandmul ti-l
ay eredlayouts.
Theyar eresponsiblefordef i
ningthel ayoutproper t
iesoftheVi ewscont ainedwi t
hinthem andof t
enov er
ride
thebasicsetti
ngs.Thi sincludeshowt heseVi ewsar epositionedanddi spl ayedont hescr een.

Belowar esomecommonv i
ewsav ai
lablei
nAndr
oid.
1.Andr oidEdi tText
2.Andr oidTextBox
3.Andr oidBut ton
4.Andr oidRadi oBut t
on
5.Andr oidCheckbox
6.Andr oidToggl eBut t
on
7.Andr oidRadi oGr oup
8.Andr oidI mageBut ton
 Edi tText:
Edit
Textisoneoft hebasi cUIwi dgets,whichi
susedtot
akei
nputf
rom t
heuser
.TheEdi
tTexti
sder
ivedori
s
theextensionoft heText ViewinAndr oid.
Syntax:
<EditText
android:
id="@+id/plain_text_i
nput"
android:
layout_
hei ght="wrap_content "
android:
layout_
wi dth="mat ch_parent"
android:
inputType="text"/>
4 MADMat
eri
al(
VL) MTDC:
PALAMANER
 Text View:
TextViewr eferstothewi dgetwhi chdispl
ayssometextonthescr
eenbasedonthel
ayout
,si
ze,
col
or,
etcset
fort
hatpar ti
cularText View.I topt i
onal
lyal
lowsust
omodi f
yorediti
tsel
faswel
l
.
Syntax:
<TextView
android:
id="@+id/text_v i
ew_ id"
android:
layout_height="wr ap_ content
"
android:
layout_width="wr ap_ content"
android:
text="@string/hello"/ >

 But t
on:
InAndroidappl i
cations, aBut t
onisauserint
erf
acet
hati
susedt
oper
for
m someact
ionwhencl
i
ckedor
tapped.
Iti
sav erycommonwi dgeti nAndr oi
dand
developer
sof tenusei t.
Syntax:
<Button
android:
id="@+id/but ton_id"
android:
layout_height=" wrap_content"
android:
layout_width=" wrap_content"
android:
text="@string/ sel
f_destruct"/
>

 ImageVi ew:
ImageViewcl assisusedt odispl
ayanykindofimager esourcei
ntheandr
oidapplicati
onei theritcanbe
android.
graphics.
Bit
maporandr oi
d.graphi
cs.drawable.Drawabl
e(iti
sageneralabstractionforany thi
ng
thatcanbedr awninAndr oi
d).ImageViewclassorandr oid.wi
dget
.I
mageVi
ewi nherit
st heandr oi
d.view.Vi
ew
classwhichisthesubclassofKot l
in.AnyCl
ass.Appli
cationofImageViewi
salsoinappl yingt i
ntstoani mage

5 MADMat
eri
al(
VL) MTDC:
PALAMANER
i
nor dertor euseadr awabl eresourceandcr eat
eoverl
aysonbackgr
oundi
mages.Mor
eov
er,
ImageVi
ewi
s
alsousedt ocont rolt
hesi zeandmov ementofanimage.
Sy nt
ax:
<ImageVi ew
android:l
ay out_
width="wrap_ content"
android:l
ay out_
height="wrap_ content"
android:src="@drawabl e/my_ i
mage"
android:contentDescripti
on="@st ri
ng/my_image_
descripti
on" />

 RadioBut t
on&RadioGroup:
Androi
dradiobuttoni
sawidgetthatcanhavemorethanoneoptiontochoosefr
om.Theusercanchoose
onlyoneopti
onatat i
me.Eachopti
onhererefer
stoaradiobut
tonandalltheopt
ionsf
orthet
opicare
toget
herref
erredtoasRadi
oGroup.Hence,RadioBut
tonsareusedinsi
deaRadioGroup.

Thisimageshows4opt i
onsoft hesubj ect
sforaquest
ion.I
nthis,eachment i
onedsubj ectisaRadioButt
on
andal lthe4subj ectst oget herar eenclosedinaRadioGroup.
<RadioGr oup <RadioButton
andr oid:
layout _mar ginTop=" 50dp" androi
d:l
ayout_
width="fil
l_par
ent"
andr oid:
id="@+i d/ gr oupr adio" androi
d:l
ayout_
height="wr ap_
content
"
andr oid:
layout _mar ginLef t
=" 10dp" androi
d:i
d="@+id/
radia_ i
d2"
andr oid:
layout _widt h=" f
ill_
par ent" androi
d:t
ext="
C/C++Pr ogramming"
andr oid:
layout _height ="wr ap_ content"
> androi
d:t
extSi
ze="20sp" /
>
<!
--InRadi oGr oupcr eat ethe1Radi oButton- <RadioButton
-> androi
d:l
ayout_
width="fil
l_par
ent"
<!--l
ikethiswewi lladdsomemor eRadio androi
d:l
ayout_
height="wr ap_
content
"
Button--> androi
d:i
d="@+id/
radia_ i
d3"
<Radi oButton androi
d:t
ext="
DataStruct ure"
androi
d:lay out_wi dt h="fil
l_parent" androi
d:t
extSi
ze="20sp" /
>
androi
d:lay out_hei ght ="wr ap_content" <RadioButton
androi
d:id=" @+i d/ radia_ i
d1" androi
d:l
ayout_
width="fil
l_par
ent"
androi
d:text ="DBMS" androi
d:l
ayout_
height="wr ap_
content
"
androi
d:text Size=" 20sp" /> androi
d:i
d="@+id/
radia_ i
d4"

6 MADMat
eri
al(
VL) MTDC:
PALAMANER
android:text="Algorit
hms" </Radi
oGroup>
android:textSize="20sp"/>
 Toggl eBut ton:
ToggleBut tonisj ustlikeaswi tchcont ainingt wost at
eseit
herONorOFFwhi char
erepr
esentedusing
bool
eanv aluestrueandf alserespect i
v el
y .Toggl eButtonunli
keswit
chdoesnothaveasl
iderint
erf
acei.
e.
wecannotsl i
det ochanget hest ates.Itisj ustlikeabut t
on.
Synt
ax:
<ToggleBut t
on
andr oid:i
d="@+i d/t
oggleBut t
on"
andr oid:l
ayout _width="wrap_ content"
andr oid:l
ayout _height="wrap_ content"
app:
layout _constraintBottom_toBot tomOf ="par ent
"
app:lay out_const r
aintEnd_toEndOf ="
par ent "
app:lay out_const r
aintStar
t_toSt ar
tOf=" par ent"
app:lay out_const r
aintTop_toTopOf ="par ent"
/>

 CheckBox:
InAndroi
d,CheckBoxi sat ypeoft wost at
ebuttonei
theruncheckedorcheckedi
nAndroid.Ory oucansayi
tis
atypeofon/ offswitchthatcanbet oggl
edbytheusers.Youshouldusecheckboxwhenpr esenti
ngagroupof
sel
ectabl
eopt ionstouser sthatar enotmut ual
l
yexclusi
ve.CompoundButtonisthepar
entclass
ofCheckBoxcl ass.
<CheckBox
androi
d:i
d="@+i d/si
mpl eCheckBox"
androi
d:l
ayout_width="wrap_ content"
androi
d:l
ayout_height="wrap_ content"
androi
d:t
ext="SimpleCheckBox" />

Vi
ewsExampl
e:
<Li
nearLayout andr
oid:
layout
_height="fi
l
l_par
ent
"
xmlns:
android="ht
tp:
//schemas.
andr
oid.com/
apk/
r andr
oid:
ori
entati
on="verti
cal">
es/
android" <TextVi
ew
androi
d:layout_
widt
h="fil
l
_par
ent
" androi
d:i
d="@+id/textView"
7 MADMat eri
al(
VL) MTDC: PALAMANER
android:l
ayout_width="mat ch_ parent" androi
d:i
d=" @+id/
radioBtton1"
android:l
ayout_height="wrap_ cont ent" androi
d:l
ay out
_width="wrap_content"
android:t
ext="
Hel l
oReader s!!"/ > androi
d:l
ay out
_height="
wr ap_content
"
<Button androi
d:checked="tr
ue"
android:i
d="@+id/buttonExampl e" androi
d:text="
RadioButton1"/ >
android:l
ayout_width="mat ch_ parent" <Radi
oButton
android:l
ayout_height="wrap_ cont ent" androi
d:i
d=" @+id/
radioButton2"
android:t
ext="
Exampl eButt on"/ > androi
d:l
ay out
_width="wrap_content"
<CheckBox androi
d:l
ay out
_height="
wr ap_content
"
android:i
d="@+id/checkBoxExampl e" androi
d:text="
RadioButton2"/ >
android:l
ayout_width="mat ch_ parent" <Radi
oButton
android:l
ayout_height="wrap_ cont ent" androi
d:i
d=" @+id/
radioButton3"
android:t
ext="
CheckBoxExampl e"/> androi
d:l
ay out
_width="wrap_content"
<ToggleButton androi
d:l
ay out
_height="
wr ap_content
"
android:i
d="@+id/toggleBut tonExampl e" androi
d:text="
RadioButton3"/ >
android:l
ayout_width="wrap_ cont ent" </
Radi
oGroup>
android:l
ayout_height="wrap_ cont ent"
android:t
ext="
Toggl eButtonExampl e"/ > <ImageButton
<RadioGr oup androi
d:i
d=" @+id/i
mageBut t
onExampl e"
android:i
d="@+id/ r
adioGroupExampl e" androi
d:l
ay out_
width="match_ par
ent"
android:l
ayout_width="wrap_ content" androi
d:l
ay out_
height="
wrap_ content
"
android:l
ayout_height="wrap_ content"> androi
d:src="@drawable/i
c_launcher"/>
<RadioBut ton </
Linear
Layout>
Appl
icat
ionCont
ext
Cont ex tist hei nterfacet hatcont ainglobal informat i
onaboutappl icati
onenv ironment .Cont extal l
owst o
accessappl icat i
on- speci ficresour ces( str
ings,themes, asset setc.)andcl asses.Li kewise,Itdeals
withappl icat ion- l
ev eloper ationssuchasl aunchi ngact ivit
ies,broadcast i
ngandr ecei vi
ngi ntents.Inshor t,
Cont extr epr esent sahandl et ogetenv ir
onmentdat a.
Wecanbr eakt heCont extandi tsusei ntot hreemaj orpoi nts:
 I tal lowsust oaccessr esour ces.
 I tal lowsust oi nter actwi thot herAndr oidcomponent sbysendi ngmessages.
 I tgi vesy oui nfor mat ionabouty ourappenv i
ronment .
RealWor ldExampl e:
Let ’
saper sonv i
sitahot el.Heneedsbr eakf ast,l
unch,anddi nneratasui t
abl etime.Exceptf ort heset hings
therear eal somanyot hert hings,hewant stododur inghi stimeofst ay .Sohowdoeshegett heset hings?
Hewi llaskt her oom- ser v i
ceper sont obr i
ngt heset hingsf orhim.Ri ght?Soher ether oom- ser viceper soni s
theCont extconsi deringy ouar et hesi ngleact ivi
tyandt hehot elt obey ourapp,f inall
y,t hebr eakf ast ,l
unch
&di nnerhavet obet her esour ces.
Ty pesofCont exti nAndr oi d
Ther ear emai nlyt wot ypesofCont extthatar eav ailableinAndr oid.
1.Appl icat ionCont ext
2.Act i
v ityCont ext
 Appl icat ionCont ext
Iti
sani nst ancet hatist hesi ngletonandcanbeaccessedi nactivityvi
aget Appl icati
onCont ext
( ).Thiscont ext
i
st iedt ot hel ifecy cleofanappl i
cat i
on.Theappl i
cationcont extcanbeusedwher eyouneedacont extwhose
l
ifecy cleissepar atef rom t hecur rentcont ex torwheny ouar epassi ngacont extbey ondt hescopeofact iv
ity.
Exampl e: Ify ouhav et ocr eat easi ngletonobj ectfory ourappl i
cat ionandt hatobj ectneedsacont ext, alway s
passt heappl icat i
oncont ext.
I
fy oupasst heact iv i
tycont exther e,itwi l
lleadtot hememor yl eakasi twi l
lkeept her eferencet ot he
activityandact ivitywi l
l notbegar bagecol l
ected.
Youonl yuseget Appl i
cat i
onCont ext ()wheny ouknowy ouneedaCont extf orsomet hingt hatmayl ivel onger
thananyot herl i
kel yCont exty ouhav eaty ourdisposal .
So,whenev ert he v ar i
abl e scope i sr equi r
ed t hroughoutt he appl i
cat i
on,we can geti tby means
8 MADMat
eri
al(
VL) MTDC:
PALAMANER
ofget
Appl i
cat i
onCont ext(
).Fol
lowi
ngisal
istoff
unct
ional
it
iesofAppl
i
cat
ionCont
ext
.
Funct
ionali
tiesofAppl icati
onContext
:
 LoadRe sourceVal ues
 StartaSer vi
ce
 Bindt oaSer vi
ce
 Se ndaBr oadcast
 Re gisterBroadcastReceiver

 Ac tivityCont ex t:
Iti
st heact ivityCont extmeani ngeachandev eryscreengotanact i
vi
ty.Forexampl e,Enquir
yAct
ivi
tyrefer
sto
Enqui r
yAct ivi
tyonl yandAddAct iv it
yrefer
st oAddAct iv
ityonly
.Iti
st i
edtothel if
ecy cl
eofactiv
ity
.Itisused
forthecur rentCont ext.Themet hodofi nvokingtheAct i
vit
yContextisgetContext()
.
SomeusecasesofAct i
v i
tyCont extare:
 Theus eriscr eatinganobj ectwhosel if
ecycl
eisat t
achedtoanact i
vit
y.
 Whe nev erinsi deanact iv
ityf orUIrelat
edkindofoper ati
onsli
ketoast,dial
ogue, et
c.,
getCont ext():
Itreturnst heCont extwhi chisl i
nkedt ot heAct i
vit
yfrom whichitiscall
ed.Thi sisusefulwhenwewantt o
calltheCont extfrom onl ythecur rentrunningactivi
ty.
Funct ionalitiesofAct i
vityContext :
 LoadRe sour ceVal ues
 Lay outI nflation
 St artanAct ivity
 ShowaDi alog
 St artaSer v ice
 Bi ndt oaSer v i
ce
 Se ndaBr oadcast
 Re gisterBr oadcastRecei v er
Act
ivi
ti
es
InAndr oid,anact ivit
yi sr eferredt oasonescr eeni nanappl icat i
on.I tisv erysi milartoasi nglewi ndowof
anydeskt opappl ication.AnAndr oidappconsi stsofoneormor escr eensoract i
v i
ti
es.
Eachact ivit
ygoest hroughv ariousst agesoral if
ecy cleandi smanagedbyact ivi
tyst acks.Sowhenanew
activitystarts, t
hepr ev i
ousoneal way sremai nsbel owi t.Ther ear ef ourst agesofanact i
vit
y .
1.I fanact ivityisi nt hef oregr oundoft hescr eeni .
eatt het opoft hest ack, theni tissai dtobeact i
veor
running.Thi si susual lytheact ivi
tythattheuseri scurrent l
yi nteractingwi th.
2.I fanact ivityhasl ostf ocusandanon- ful
l-sizedort r
anspar entact i
vityhasf ocusedont opofy ouract iv
ity
.
Insuchacaseei theranot heract i
vit
yhasahi gherposi t
ioni nmul ti
-windowmodeort heact ivi
tyi t
selfis
notf ocusabl ei nt hecur rentwi ndowmode.Suchact ivit
yi scompl etelyaliv e.
3.I fanact ivityiscompl etelyhi ddenbyanot heract ivi
ty,i
tisst oppedorhi dden.I tstillretainsallthe
i
nf ormat ion,andasi tswi ndowi shiddent husi twi l
loftenbeki l
ledbyt hesy stem whenmemor yi sneeded
elsewher e.
4.Thesy stem candest royt heact ivi
tyfrom memor ybyei theraski ngi ttof inishorsi mpl ykill
i
ngi tspr ocess.
Wheni tisdi spl ayedagai nt otheuser ,i
tmustbecompl etelyr estartedandr estoredt oitspreviousst ate.
Act i
v i
tyLi f
ecy clei nAndr oid
Andr oidpr ov i
desuswi thasetof7met hodst hathav etheirownsi gni f
icancef oreachst ageint hel i
fecy cl
e.
Thei mageshowsapat hofmi grationwhenev eranappswi tchesf rom onest at etoanot her.
1.onCr eate()
Itiscal l
edwhent heact i
vityi sfir
stcr eated.Thi siswher eall thest aticwor kisdonel ikecr eat i
ngv iews,
bindingdat at olists,et c.Thi smet hodal sopr ovidesaBundl econt ainingi tspr eviousf rozenst ate,ifthere
wasone.
2.onSt art(
)
Itisinv okedwhent heact ivi
tyisv isibletotheuser .Itisfoll
owedbyonResume( )iftheact i
vityisinv okedf r
om
thebackgr ound.I tisal soi nv okedaf teronCr eate()whent heact ivityisf i
rstst arted.
9 MADMat eri
al( VL) MTDC: PALAMANER
3.onRest art
()
Iti
sinv okedaftert heact i
v it
yhasbeenst oppedandpr iortoitsst artingst ageandt husisal way sfoll
owedby
onStart()whenanyact ivityisrev ivedf rom backgr oundt oon- screen.
4.onResume( )
Iti
sinv okedwhent heact iv i
tystar tsinteract ingwi t
ht heuser .Att hispoi nt,theact ivi
tyisatt hetopoft he
acti
vit
yst ack,withauseri nter
act ingwi thi t.Al way sf oll
owedbyonPause( )whent heact iv
itygoesi ntot he
backgroundori sclosedbyt heuser .
5.onPause( )
Iti
sinv okedwhenanact i
v i
tyisgoi ngint ot hebackgr oundbuthasnoty etbeenki ll
ed.Itisacount erpar tto
onResume( )
.Whenanact ivi
tyisl aunchedi nf rontofanot heract i
vity,thiscal l
backwi l
lbei nv okedont het op
acti
vit
y( curr
ent l
yonscr een) .Theact ivi
ty ,undert heact i
veact ivit
y ,
wi llnotbecr eatedunt iltheact i
ve
acti
vit
y ’
sonPause( )r et
ur ns, soi tisrecommendedt hatheav ypr ocessi ngshoul dnotbedonei nthispar t.
6.onSt op()
Iti
sinv okedwhent heact iv i
tyisnotv isiblet ot heuser .Iti
sf ollowedbyonRest art(
)whent heact ivi
tyis
revokedf r
om thebackgr ound, foll
owedbyonDest roy ()whent heact iv i
tyiscl osedorf i
nished, andnot hi ng
whent heact i
vityremai nsont hebackgr oundonl y.Not et hatt hismet hodmaynev erbecal led,inlowmemor y
sit
uationswher et hesy stem doesnothav eenoughmemor ytokeept heact ivit
y ’
spr ocessr unningaf teri t
s
onPause( )met hodi scal led.
7.onDest roy()
Thef i
nalcallreceiv edbef oretheact ivit
yi sdest royed.Thi scanhappenei therbecauset heact iv
ityisfinishing
(whenf ini
sh()isinv oked)orbecauset hesy stem ist empor aril
ydest roy ingthisi nstanceoft heact i
vit
yt o
savespace.Todi st inguishbet weent hesescenar i
os, checki twi thisFi nishing()met hod.

10 MADMat
eri
al(
VL) MTDC:
PALAMANER
Exampl e:
packagecom. exampl e.helloworld;
i
mpor tandr oi
d.os.Bundl e;
i
mpor tandr oi
d.app.Activ i
ty;
i
mpor tandr oi
d.uti
l.
Log;
publi
ccl assMai nActivi
tyext endsAct ivi
ty{
Stri
ngmsg=" Andr oid: ";
@Ov er ri
de
publicv oi
donCr eat e(
Bundl esav edInstanceSt
ate){
super .
onCreate(savedI nstanceState);
setContentView(R. l
ay out.
activi
ty_main);
Log.d(msg, "TheonCr eate()event")
;
}

@Ov erri
de }
protectedv oi
donSt art(){
super .onStart
();
Log. d(msg, "
TheonSt art
()event"
);
} Andr oidMani fest .
xmlf i
le
/**Calledwhent heact i
vit
yhasbecomev isible.*
/
@Ov er
ride <?xml ver sion=" 1.0"encodi ng=" utf-
8"?>
protectedv oi
donResume( ){ <mani fest
super .onResume( ); xmlns:andr oi
d=" http://schemas. android.com/apk/r
es/a
Log. d(msg, "
TheonResume( )event"
); ndroid"
}
/**Calledwhenanot heract i
vi
tyistakingfocus.* / package=" com. exampl e.
tutorialspoint7.my appli
cat
ion"
>
@Ov er
ride <ap pli
c ation
andr oid:allowBackup=" true"
protectedv oi
donPause( ){
andr oid:icon=" @mi pmap/ ic_launcher "
super .onPause(); andr oid:label="@st ri
ng/ app_ name"
Log. d(msg, "
TheonPause( )event")
; andr oid:suppor tsRt l
="t
rue"
} andr oid:theme=" @st yl
e/AppTheme" >
/**Calledwhent heact i
vit
yisnolongerv isible.*/ <act ivit
yandr oid:name=" .Mai nActi
v it
y">
@Ov er
ride <i ntent-fil
ter>
protectedv oi
donSt op( ){ <act ion
super .onStop(); andro i
d :
n ame ="androi d.i
ntent .
act i
on.MAI N"/ >
Log. d(msg, "
TheonSt op()event
");
<cat egor y
}
android:name=" androi d.i
ntent .
cat egory.LAUNCHER"/ >
/**Calledjustbef oretheactivi
tyisdestroy ed.*/ </ intent -
fil
ter>
@Ov er
ride </act ivit
y>
publicvoidonDest r
oy(){ </appl icati
on>
super .onDestroy(); </mani fest >
Log. d(msg, "
TheonDest roy(
)event");
}
Servi
cesi
nAndroid

Servi
cesinAndr oidareaspecialcomponentt hatfaci
li
tatesanapplicationtoruni nt hebackgroundi norder
toperfor
ml ong-runningoper
ationtasks.Theprimeai m ofaservi
cei stoensur et hattheappli
cationr emains
acti
veinthebackgr oundsothattheusercanoper at
emul ti
pleappl
icat i
onsatt hesamet i
me.Auser -
i
nterf
aceisnotdesi rablef
orandroidservi
cesasi tisdesignedtooper atelong-runningprocesseswi thout
anyuserint
er v
ent i
on.Aservi
cecanr uncontinuouslyinthebackgroundev eniftheappl i
cati
oni sclosedor
theuserswitchest o

anot
herappl
icat
ion.
11 MADMat
eri
al(
VL) MTDC:
PALAMANER
Ty
pesofAndr
oidSer
vices alsopauseandr esumet hepr ocess.
2.BackgroundSer vices:
Backgr oundser vicesdonotr equireanyuser
interv ention.Theseser vicesdonotnot if
ythe
useraboutongoi ngbackgr oundt asksand
user sal socannotaccesst hem.Thepr ocess
li
keschedul esy ncingofdat aorst oringofdat a
fallundert hisser vi
ce.
3.BoundSer vices:
Thi st ypeofandr oidserviceal l
owst he
component soft heapplicationlikeact ivit
yto
boundt hemsel veswi t
hi t.Boundser v i
ces
per formt heirtaskaslongasanyappl i
cation
1.For
egroundSer vices:
componenti sboundt oi t.Mor ethanone
Servi
cest hatnot i
fytheuserabouti t
songoing
componenti sallowedt obi ndthemsel veswi t
h
operationsar et ermedasFor egroundServi
ces.
aser viceatat ime.Inordert obindan
Userscani nteractwiththeserv i
cebythe
appl icationcomponentwi t
haser vicebi nd
noti
ficati
onspr ov i
dedabouttheongoi ngt
ask.
Ser vice( )met hodi sused.
Suchasi ndownl oadingafil
e,theusercankeep
tr
ackoft hepr ogressi ndownloadingandcan

TheLi
feCy
cleofAndr
oidSer
vices:
Inandr oi
d, ser vi
ceshav e2possi blepat hst ocompl eteitsli
fecy clenamel y
1.St art
edSer v
ice
2.BoundedSer vice.
1.St art
edSer vice( UnboundedSer vice):
Byfollowi ngt hispath,aser vicewi llini
t i
atewhenanappl icationcomponentcal l
s
thestar tService()method.Oncei nitiated,theser vi
cecanr uncont i
nuouslyinthebackgroundev enifthe
componenti sdestroyedwhi chwasr esponsi bl
ef orthestartoft heservi
ce.Twoopt i
onareavail
ablet o
stoptheexecut i
onofser vice:
 Byc all
ingst opService()met hod,
 Thes ervicecanst opi tselfbyusi ngst opSelf(
)met hod.
2.BoundedSer vice:
Itcanbet reatedasaser v
eri nacl ient-serv erinter
face.Byfollowi ngthispath,androidappl
icat
ion
component scansendr equest st ot heser v i
ceandcanf etchresul ts.Aservi
cei stermedasboundedwhenan
appl i
cati
oncomponentbi ndsi tselfwi t
haser vicebycalli
ngbi ndSer vi
ce()method.Tost optheexecutionof
thisservice, allthecomponent smustunbi ndt hemsel v
esf r
om t heser vi
cebyusi ngunbindServi
ce()met hod.

12 MADMat
eri
al(
VL) MTDC:
PALAMANER
Tocarr
youtadownloadi
ngtaskinthebackground,
thestar
tServi
ce(
)methodwil
lbecal
l
ed.Wher eastoget
i
nfor
mat i
onr
egar
dingthedownloadprogressandtopauseorresumethepr
ocesswhi
letheappl
icati
onis
st
il
li
n

t
hebackgr
ound,
theser
vicemustbeboundedwi
thacomponentwhi
chcanper
for
mtheset
asks.

I
ntent
s

(
OR)
l
inki
ngact
ivi
ti
eswi
thI
ntent
s
Anintentisamessagi ngobjectusedt or
equestanyacti
onfrom anot
herappcomponent.Int
entsfacil
it
ate
communi cati
onbetweendiff
erentcomponentsinsev
eralways.Theint
enti
susedtolaunchanactiv
ity,star
t
theservi
ces,broadcastr
ecei
vers,displ
ayawebpage,dialaphonecall
,sendmessagesfrom oneacti
v i
tyto
anot
heract i
vi
ty,andsoon.
Androi
dintentsaremainl
yusedt o:

o St
artt
heser
vice

o Launchanact
ivi
ty

o Di
spl
ayawebpage

o Di
spl
ayal
i
stofcont
act
s

o Br
oadcastamessage

o Di
alaphonecal
let
c.

I
mpor
tanceofusi
ngI
ntent
sinAndr
oidAppl
icat
ions:
Whenev eryouneedtonavigatetoanot
heract i
vi
tyofy ourapporyouneedtosendsomeinf
ormationt
onext
acti
vi
tythenwecanal waysprefert
oInt
entsfordoingso.
I
ntentsar ereal
l
yeasyt ohandl eandi tfacil
it
atescommuni cati
onofcomponentsandactivi
ti
esofyour
appli
cati
on.Moreoveryoucancommuni cat
et oanotherappli
cat
ionandsendsomedatat
oanotherappl
i
cat
ion
usi
ngI ntent
s.
TYPESOFI
NTENT:
I
ntent
sareoftwotypes:
1.Expl
ici
tint
ent
2.Impl
ici
tint
ent

13 MADMat
eri
al(
VL) MTDC:
PALAMANER
EXPLI
CITI
NTENT:
Expli
citintentsarecommuni catedbetweentwoactiv
iti
esinsi
dethesameappl
i
cat
ion.Wecanuseexpl
ici
t
i
ntentswhenweneedt omov efrom oneacti
vit
ytoanotheract
ivi
ty.
Exampl e:-whenauserwant stostartaservi
cetodownloadafil
eorwhenanewacti
vit
yget
sstar
tedin
responset oauseract i
on.
//Expli
citIntent
Intentsend=newI nt
ent(Fi
rstAct
ivt
iy.
thi
s,SecondActi
vit
y.cl
ass)
;
//Start
sTar getAct
ivi
ty
startActi
vi
t y
(send)
;
Exampl e:-
avti
vit
y _mai n.
xml
<?xml v er si
on=" 1.0"encodi ng=" utf-8"?> <RelativeLayout
<Rel ativeLay out xmlns: android="
ht t
p://schemas.android.
com/apk/r
es/
a
xml ns: andr oid=" htt
p://schemas. andr oi d.
com/ apk/r
es/a ndroid"
ndroi d" xml ns:tools="
http://
schemas. android.
com/
tools"
xml ns: tools="http://
schemas. andr oid.com/tools" andr oid:l
ayout_width="match_parent"
andr oid: l
ayout _width=" mat ch_ par ent " andr oid:l
ayout_height="match_parent"
andr oid: l
ayout _height="mat ch_ par ent "
tools:cont ext="com. exampl e.appl icat i
on. myappli
cati
on. tools:context="com.exampl e.appli
cation.my appl
i
cat
ion.
Mai nAct ivity
"> Activity
2">
<Text Vi ew <!-
-newact i
vi
t ystar
tandAct i
v i
ty2-->
andr oid:i
d=" @+id/ textVi ew" <Text View
andr oid:l
ay out_widt h="wr ap_ cont ent " android:
id="@+id/textView"
andr oid:l
ay out_height ="wr ap_ cont ent" android:
layout_width="wrap_cont ent"
andr oid:l
ay out_cent erHor izont al="true" android:
layout_height="
wr ap_cont ent"
andr oid:l
ay out_cent erVer ti
cal ="true" android:
layout_centerHorizontal
=" tr
ue"
andr oid:text="Thisi sFir stAct ivi
ty "/> android:
layout_centerVerti
cal="t
rue"
<!-
-openact i
v i
ty2-->
<But ton andr
oid:
text
="Thi
sisSecondAct
ivi
ty"/
>
andr oid:i
d=" @+id/ button" <But
ton
andr oid:l
ay out_widt h="wr ap_ cont ent " andr
oid:
i
d="@+id/but
ton"
andr oid:l
ay out_height ="wr ap_ cont ent"
andr oid:l
ay out_below=" @i d/text View" andr
oid:
l
ay out
_width="wrap_content"
andr oid:l
ay out_cent erHor izont al="true" andr
oid:
l
ay out
_height="
wr ap_content"
andr oid:text="GOTOOTHERACTI VITY"/> andr
oid:
l
ay out
_below="@i d/t
extView"
</Rel ativ eLay out> andr
oid:
l
ay out
_centerHorizontal
="tr
ue"
activity_ 2.xml andr
oid:
text="
openact i
vi
ty2"/ >
<?xml v er si
on=" 1.0"encodi ng=" utf-8"?>
<!-
-act ivity _
2--> </
Rel
ati
veLay
out
>

Mai
nAct
ivi
ty.
Jav
a

packagecom.exampl e.appl i
cat
ion.
myappl
i
cati
on; publi
cclassMai
nActi
vi
tyext
endsAppCompat
Act
ivi
ty{
i
mpor tandr
oid.
content.Intent; pri
vateButt
onbut
ton;
i
mpor tandr
oid.
suppor t.
v 7.
app.AppCompatAct
ivi
ty;
i
mpor tandr
oid.
os.Bundl e; @Ov err
ide
i
mpor tandr
oid.
vi
ew. View; prot
ectedv oidonCreate(Bundlesav edI
nstanceSt
ate){
i
mpor tandr
oid.
widget .
But ton; super.
onCr eate(
savedInstanceState);
setContentView(R.
layout.
activi
ty_main);
14 MADMat
eri
al(
VL) MTDC:
PALAMANER
privateBut tonbut t
on;
but
ton=(But
ton)f
indViewByI
d(R.
id.
butt
on); @Ov er r
ide
but
ton.
set
OnCli
ckList
ener(
newView.OnCli
ckLi
stener
() protect edv oi donCr eat e(Bundl esav edInstanceState){
{ super .
onCr eat e( savedI nstanceSt ate);
@Ov err
ide setCont ent View( R.lay out.activi
ty_2);
publi
cvoidonCli
ck(
Viewv
){ but ton=( But ton)f indVi ewBy I
d(R.i
d.button);
openActi
vit
y2(
); but ton.setOnCl ickLi stener (
newVi ew.OnCl i
ckListener
()
} {
}
); @Ov erri
de
} publ i
cv oidonCl i
ck( Viewv ){
/ /Backt ot heMai nActivit
y
publicvoidopenAct i
vit
y 2(
){ openAct ivi
ty 1();
//Expli
citIntent }
Intentintent=newI ntent(
thi
s,Acti
vi
ty2.
class)
; });
startActi
v i
ty(
intent)
; }
} publ i
cv oi
dopenAct ivity1(){
OUTPUT: //Expl ici
tInt ent
} Intenti ntent=newI ntent(this,Mai nActi
vity.
class);
Activit
y2.Java start Activi
ty (
int ent);
packagecom. exampl e.appli
cati
on.myappl
icati
on; }
i
mpor tandroid.support.
v 7.
app.
AppCompat Activ
ity
; }
i
mpor tandroid.os.Bundle;

publ
i
ccl
assAct
ivi
ty2ext
endsAppCompat
Act
ivi
ty{

IMPLICI TI NTENT:
Impli
citintenti scommuni cat edbetweent woactiv
iti
esofanappl
icat
ion.Onet hi
ngtonoteher
eisweshoul
d
notnameaspeci f
iccomponent .Inplaceofthatwecandeclar
eagener alacti
ontoperf
orm whi
chal
l
owsa
componentf r
om anot herappt ohandl eit
.
Exampl e:-Toshowt heuseral ocationonamap, wecanuseani mpli
citintent
.
//I
mpl i
citintent
Intentint ent=newI ntent();
i
nt ent.setAct i
on(andr oi
d.content.
Int
ent.
ACTION_ VI
EW);
i
nt ent.setDat a(Cont
r act.
Cont act
s.CONTENT_ URL);
star t
Activ i
ty(i
ntent)
;
Exampl e:-activi
ty _main.xml
<?xml ver si
оn=" 1.0"
enсоding=" utf-8"?>

15 MADMat
eri
al(
VL) MTDC:
PALAMANER
<! -
-асt ivit
y _mаi n-->
<Rel аtiveLаy оutxml ns: аndr оid=" ht tр://
sсhemаs. аndrоid.
соm/арk/r
es/аndr
оid"<!
--
аndrоi
d-->
<! -
-def аultl аyоutst ruсt ure-->
xmlns: tооls=" httр: // sсhemаs. аndrоi d.соm/ tооls"<! --t
ооls-
->
xmlns: арр=" ht tр:/ /sсhemаs. аndr оid.соm/ арk/res-аut о"<!-
-арр-
->
tооls: соnt ext=" соm. exаmрl e.imрliсitintent.MаinАсt i
vity
"
аndrоi d:lаyоut _ wi dt h=" mаt сh_ раrent"<! -
-fоrwidt h-->
аndr оid: l
аy оut _hei ght=" mаt сh_ раrent "<!--fоrheight -->>
<! -
-inрutf ieldf оrwr itingwebsi tenаme- ->
<Edi tText
<! -
-f
оri nрutf ield- ->
аndr оid: i
d=" @+i d/ edi tText "<! --
edittextidnаme- ->
аndr оid: l
аy оut _wi dt h=" wr ар_ соntent "<! -
-fоrwidt h-->
аndr оid: l
аy оut _hei ght=" wr ар_ соntent "<!--fоrheight -
->аndr оi
d:l
аyоut_mаrgi
nEnd="7dр"<!-
-mаrgi
nаtt
he
end-->
аndr оid: l
аy оut _mаr ginSt аrt=" 7dр"<! --mаrgi nаtt hest аrt
-->
аndr оid: l
аy оut _mаr ginTор=" 70dр"<! -
-mаr ginаtt het ор-->
аndr оid: ems=" 9"<
!-
-f
оrаl i
gnment -->
аndr оid: l
аy оut _аl ignРаr ent Tор=" t
rue"
аndrоi d:lаyоut _ сent er Hоr izоnt аl ="t
rue"/>
<! -
-Орenwebраge- ->
<But tоn
аndrоi d:id=" @+i d/ but tоn"<! -
-but t
оni dnаme- ->
аndr оid: l
аy оut _wi dt h=" wr ар_ соntent "<! -
-fоrwidt h-->
аndr оid: l
аy оut _hei ght=" wr ар_ соntent "<!--fоrheight -
->

<! -
-butt
оnbelоwedi t
Text-
->
аndrоid:l
аyоut_bel
оw=" i
d/edit
Text"
аndrоid:l
аyоut_сenterHоri
zоntаl="t
rue"
аndrоid:l
аyоut_mаrginTор=" 172dр"
аndrоid:l
аyоut_mаrginRight="8dр"
аndrоid:l
аyоut_mаrginLeft="156dр"<
!
--di
sрlаytext-
->
аndrоid:t
ext=" Vi
sit"/>
</ Relаt
iveLаyоut>
Mai
nAct
ivi
ty.
jav
a
packagecom. exampl e.i
mpl i
citi
ntent;//packagename
i
mpor tandroid.cont ent.I
ntent ;
i
mpor tandroid.net .Uri
;
i
mpor tandroid.suppor t.
v7.
app. AppCompat Activi
ty;
i
mpor tandroid.os. Bundle;
i
mpor tandroid.view. View;
i
mpor tandroid.wi dget .
Button;
i
mpor tandroid.wi dget .
Edit
Text ;
publi
cclassMai nAct ivi
tyext endsAppCompat Acti
vi
ty{
Butt
onbut ton; //button
Edit
TexteditText ; //
inputtext
@Ov erri
de
prot
ectedv oidonCr eate(Bundl esav edInst
anceState){
super.onCreate( savedInstanceSt ate);
setContentView( R.layout.activ
ity
_ main);
button=f i
ndVi ewBy I
d(R.id.butt
on);
16 MADMat
eri
al(
VL) MTDC:
PALAMANER
edit
Text=f indViewBy Id(R.i
d.edi
tText);
butt
on. setOnCl i
ckLi stener(newVi ew.OnCli
ckList
ener
(){//addthel
i
steneronbut
ton
@Ov er r
ide
publi
cv oidonCl i
ck( Viewv iew){
//
stringt ypev ariable
Str
ingur l =editText .getText()
.
toSt r
ing( )
;//forst oringedtit
extvalue
//
Intentobj ectandopent hewebpage
I
ntenti ntent=newI ntent(Int
ent.ACTION_VIEW,Uri
.par
se(url
))
;
startAct i
vity
(intent);//callawebpage
}
})
;
}
}
Output:
-

Recei
vi
ngandBr oadcasti
ngIntents
Androidappssendandr eceivebroadcastmessagesf rom theAndroi
dsy st
em andot herAndr
oidapps,simi
lar
tothepubli
sh-subscribedesignpattern.Thesystem andappst ypi
cal
lysendbr oadcastswhencer t
ainevent
s
occur.Forexample,theAndr oidsystem sendsbroadcastswhenv ari
oussy st
em ev entsoccur
,suchassy st
em
bootordev i
cecharging.Appsal sosendcust om broadcast
s,forexample,tonotif
yot herappsofsomething
thatmightint
erestthem (forexample, newdatadownl oad)
.

Appscanregist
ert
or ecei
vespeci
fi
cbroadcasts.Whenabroadcasti
ssent,
thesyst
em aut
omat
ical
l
yrout
es
br
oadcast
st oappsthathavesubscr
ibedtoreceiv
ethatpar
ti
cul
artypeofbr
oadcast
.

General
lyspeaki
ng,broadcast
scanbeusedasamessagingsystem acr
ossappsandoutsi
deofthenor
mal
userfl
ow.Howev er
,youmustbecar ef
ulnott
oabusetheoppor
tuni
tytorespondt
obroadcast
sandrunjobsi
n
thebackgroundt
hatcancont r
ibut
etoaslowsyst
em per
for
mance.

BroadcastReceiver
s:
BroadcastReceiver
ssimplyrespondtobroadcastmessagesf r
om otherappli
cati
onsorf rom t
hesy stem it
sel
f.
Thesemessagesar esomet i
mecal l
edeventsorintent
s.Forexample,appl
icat
ionscanal soini
tiat
ebr oadcast
s
toletotherappl
i
cationsknowt hatsomedatahasbeendownl oadedtothedev i
ceandi sav ai
l
ablef orthem t
o
use,sothisisbr
oadcastrecei
verwhowilli
nterceptthi
scommuni cat
ionandwi l
li
niti
ateappropriat
eact i
on.

Therear
efol
l
owi
ngt
woi
mpor
tantst
epst
omakeBr
oadcastRecei
verwor
ksf
ort
hesy
stem br
oadcast
ed
i
ntents−

17 MADMat
eri
al(
VL) MTDC:
PALAMANER
 Cr
eati
ngt heBroadcastRecei
ver
.
 Regi
ster
ingBroadcastReceiv
er
Ther ei
soneaddi ti
onal stepsincasey ouar egoi ngt oimpl ementy ourcustom i
ntent
sthenyouwil
lhav
eto
createandbr oadcastthosei nt
ents.
Creat i
ngt heBr oadcastRecei ver:
Abr oadcastreceiveri
si mplement edasasubcl assofBr oadcastRecei
v ercl
assandoverr
idi
ngt
heonRecei
ve(
)
met hodwher eeachmessagei sreceiv
edasaI nt entobj ectparameter.
publicclassMy ReceiverextendsBr oadcast Recei ver{
@Ov erri
de
publ i
cv oi
donRecei ve(Contextcontext,Intentint ent){
Toast .
makeTex t(
cont ext
,"I
ntentDet ected."
, Toast .LENGTH_ LONG).show();
}
}

Regi
ster
ingBr
oadcastRecei
ver:
Anappli
cati
onl
istensf
orspeci
fi
cbr oadcasti
ntentsbyregist
eri
ngabroadcastr
eceiver
nAndr
i oidMani
fest.
xmlfi
l
e.Considerwear egoingtoregi
sterMyRecei
verforsy
stem gener
atedevent
ACTI
ON_ BOOT_COMPLETEDwhi chi sfi
redbythesystem oncetheAndroi
dsystem hascomplet
edtheboot
pr
ocess.

Nowwhenev ery ourAndr oiddevi


cegetsboot
ed,itwil
lbeint
ercept
edbyBroadcastReceiverMyRecei
verand
i
mplement edl ogicinsideonReceive(
)will
beexecuted.
Therearesev eralsystem generatedevent
sdefi
nedasf i
nalst
aticf
iel
dsi
ntheIntentclass.Thefol
lowi
ngt abl
e
l
ist
saf ewi mpor tantsy st
em events.

Sr
.No Ev
entConst
ant&Descr
ipt
ion

androi
d.i
ntent.
acti
on.
BATTERY_
CHANGED
1 Sti
ckybroadcastcont
aini
ngt
hechar
gingst
ate,
lev
el,
andot
heri
nfor
mat
ionaboutt
he
batt
ery
.

androi
d.i
ntent
.act
ion.
BATTERY_LOW
2
I
ndicat
eslowbat t
erycondi
ti
ononthedev
ice.

androi
d.i
ntent
.acti
on.
BATTERY_OKAY
3
I
ndicat
esthebat t
eryi
snowokayaft
erbei
ngl
ow.

andr
oid.
int
ent.act
ion.
BOOT_ COMPLETED
4
Thi
sisbroadcastonce,af
terthesy
stem hasf
ini
shedboot
ing.

andr
oid.
intent
.act
ion.
BUG_REPORT
5
Showactiv
ityforr
eport
ingabug.

6 andr
oid.
int
ent
.act
ion.
CALL
18 MADMat
eri
al(
VL) MTDC:
PALAMANER
Per
for
m acal
ltosomeonespeci
fi
edbyt
hedat
a.

andr
oid.
int
ent.act
ion.
CALL_BUTTON
7 Theuserpressedthe"cal
l
"but
tontogot
othedi
alerorot
herappr
opr
iat
eUIf
orpl
aci
nga
cal
l.

andr
oid.
int
ent.
acti
on.DATE_
CHANGED
8
Thedatehaschanged.

andr
oid.
int
ent.
acti
on.REBOOT
9
Havethedevi
cereboot.

Andr
oidMani
festFi
leandi
tscommonset
ti
ngs
Everypr ojecti
nAndr oidincludesaMani festXMLf i
le,whi
chi sAndr oi
dMani fest.
xml ,
locat edinther oot
directoryofitsprojecthi erarchy.Themani festf i
lei
sani mpor t
antpar tofourappbecausei tdefi
nest he
structureandmet adat aofourappl i
cati
on, i
tscomponent s,andi t
sr equir
ement s.Thisfileincludesnodesf or
eachoft heActivit
ies, Services,ContentPr oviders,andBroadcastRecei versthatmaket heapplicati
on, and
usingI ntentFil
tersandPer missionsdetermineshowt heycoor di
natewi theachot herandot herapplicati
ons.
Themani f
estfi
lealsospeci fi
est heappli
cat i
onmet adata,whichincludesi t
sicon, ver
sionnumber ,
themes,
etc.,
Amani festfi
leincludest henodest hatdefinet heappli
cati
oncomponent s,
securitysettings,testclasses,
andr equi r
ement sthatmakeupt heappli
cat i
on.Someoft hemani festsub-nodet agsthatar emai nlyusedar e:
1.mani f
est:
The mai n componentoft he Andr oidMani f
est.
xmlf i
lei s known as mani fest.Addi ti
onal l
y,the
packagingf ielddescr ibestheactivi
tycl ass’
spackagename.I tmustcont ainan<appl icat
ion>el ement
wi t
hthexml ns:androidandpackageat tri
but
especi f
ied.

<?xmlversi
on="1.
0"encoding="utf-
8"?>
<manifestxmlns:
andr
oid="htt
p://schemas.androi
d.com/
apk/
res/
andr
oid"
xmlns:
tool
s="ht
tp:
//schemas. androi
d.com/tool
s"
package="
com.example.geeksforgeeks">

<!-
-mani festnodes- ->
<appl i
cat ion>
</appl i
cat ion>
</mani fest >
2.uses-sdk:
Iti
susedt odef ineami nimum andmaxi mum SDKv er
sionbymeansofanAPILev eli
ntegerthatmust
beav ail
abl eonadev i
cesot hatourapplicati
onf uncti
onspr oper
ly,
andt het ar
getSDKf orwhi chi
thas
been desi gned usi ng a combi nati
on ofmi nSdkVersi
on,maxSdkVer sion,and targetSdkVersi
on
attr
ibutes, respectivel
y.Itiscont ai
nedwi thi
nt he<manifest>element.
<uses-sdk
android: mi nSdkVersi
on=" 18"
android: targetSdkVersion="27"/>
3.uses-permissi on
Itoutl
inesasy stem permi ssionthatmustbegr ant
edbyt heuserfortheappt ofunct
ionpr operl
yand
i
scont ainedwi thinthe<mani fest
>el ement .Whenanappl i
cati
onisi nstall
ed(onAndr oid5. 1and
l
owerdev i
cesorAndr oid6. 0andhi gher)
,theusermustgr anttheappl
icationpermissi
ons.
<uses-per mi ssion
android: name=" android.permission.
CAMERA"
android: maxSdkVer sion=" 18"/>

19 MADMat
eri
al(
VL) MTDC:
PALAMANER
4.appl
ication
Amani festcancont ainonl yoneappl icati
onnode.I tusesattr
ibutestospeci
fythemet adataforyour
appl ication( i
ncludingi tstitl
e, icon, andt heme) .Dur
ingdev el
opment ,weshoul
dincludeadebuggabl e
attributesett ot r
uet oenabl edebuggi ng,t henbesur et odisableitforyourreleasebuilds.The
appl icationnodeal soact sasacont ainerf ort heActi
vity
,Service,Cont
entProvi
der ,andBroadcast
Recei v
ernodest hatspeci fyt heappl icationcomponent s.Thenameofourcust om appl i
cat
ionclass
canbespeci fi
edusi ngt heandr oid:nameat t
ribute.
<appl i
cat i
on
andr oid:
name=" .
GeeksFor Geeks"
andr oid:
allowBackup=" true"
andr oid:
dat aExtractionRul es=" @xml /data_ext r
act
ion_rul
es"
andr oid:
fullBackupCont ent ="@xml /backup_ r
ules"
andr oid:
icon="@dr awabl e/gf gIcon"
andr oid:
label="@st r
ing/app_ name"
andr oid:
roundI con=" @mi pmap/ i
c_ l
auncher _r
ound"
andr oid:
suppor tsRt l
="tr
ue"
andr oid:
theme=" @andr oid: styl
e/ Theme. Li
ght "
andr oid:
debuggabl e="tr
ue"
tools:targetApi="31" >

<!--appl icationnodes- -
>
</appl i
cation>
5.uses-l
ibrar y
Itdef inesashar edl ibraryagai nstwhi chtheappl icationmustbel inked.Thi sel ementi nst
ructst he
system t oaddt hel ibrary ’
scodet othepackage’ sclassl oader.Itiscont ainedwi thinthe<appl i
cation>
element .
<uses- li
brary
andr oid:
name=" andr oid.test
.runner"
andr oid:
requi red=" true"/ >
6.acti
vity
TheAct ivi
tysub- elementofanappl icat
ionr efer
st oanact ivitythatneedst obespeci fi
edi nt he
Andr oi dMani fest.xmlf i
le.Ithasv ari
ouschar act
eristics,li
kel abel,name,t heme,l aunchMode,and
other s.I nt hemani festf il
e,allelement smustber epresentedby<act i
vit
y>.Anyact i
vi
tythatisnot
declar edt her ewon’ tr unandwon’ tbev isi
blet othesy stem.Iti scont ai
nedwi t
hi nthe<appl i
cation>
element .
<activi ty
andr oid:
name=" .
Mai nAct i
vit
y"
andr oid:
expor t
ed=" tr
ue" >
</act ivity>
7.i
ntent-fi
lter
Itist hesub- elementofact i
vi
tyt hatspecifiesthet ypeofi nt enttowhi cht heact i
vi
ty,servi
ce,or
broadcastr eceivercansendar esponse.I tall
owst hecomponentt or eceiveintent sofacer tai
nt ype
whilef il
ter
ingoutt hoset hatar enotusef ulforthecomponent .Thei ntentf i
lt
ermustcont ai
natl east
one<act i
on>el ement .
<intent -fi
lt
er >
<act i
onandr oid:name=" android.
intent.
acti
on. MAIN"/ >

<categoryandroi
d:name="androi
d.i
ntent.
category.
LAUNCHER"/ >
</int
ent-f
il
ter>
8.act
ion
Itaddsanact i
onfortheint
ent-f
il
ter.I
tiscontainedwithi
nthe<i
ntent-
fi
lt
er>el
ement
.
<acti
onandr oi
d:name="andr
oid.i
ntent.
acti
on.MAI N"/>

20 MADMat
eri
al(
VL) MTDC:
PALAMANER
9.category
Itaddsacat egor ynamet oani ntent -fi
l
t er.I tiscont ainedwi t
hi nthe<intent-fil
ter>el
ement .
<categor yandr oid: name=" andr oid.intent .cat egor y.
LAUNCHER"/ >
10.uses-configur at i
on
Theuses- conf igur at ioncomponent sar eusedt ospeci fythecombi nationofi nputmechani smst hat
aresuppor tedbyourappl icat ion.I tisusef ulf orgamest hatr equirepar t
icularinputcontrol
s.
<uses- conf igur at i
on
andr oid:reqTouchScr een=” fi
nger ”
andr oid:reqNav igat ion=” trackbal l”
andr oid:reqHar dKey boar d=” true”
andr oid:reqKey boar dTy pe=” qwer ty”/>
<uses- conf igur at i
on
andr oid:reqTouchScr een=” fi
nger ”
andr oid:reqNav igat ion=” trackbal l”
andr oid:reqHar dKey boar d=” true”
andr oid:reqKey boar dTy pe=” twel vekey ”/>
11.uses-features
Itis used t o speci fywhi ch har dwar ef eatur es yourappl i
cation requires.Thi s wil
lpr eventour
applicationf rom bei ngi nst al l
edonadev i
cet hatdoesnoti ncludear equir
edpi eceofhardwar esuch
asNFChar dwar e, asf ol l
ows:
<uses- feat ur eandr oi d:name=” andr oid.har dwar e.nfc”/>
12.permission
Iti
susedt ocr eat eper mi ssi onst or estr i
ctaccesst osharedappl icati
oncomponent s.Wecanal souse
theexist ingpl atfor m per mi ssi onsf orthi spur poseordef iney ourownper mi ssionsinthemani fest
.
<permi ssi on
andr oid: name=” com. paad. DETONATE_ DEVI CE”
andr oid:pr ot ect ionLev el =“danger ous”
andr oid:label =” Sel fDest ruct ”
andr oid:descr iption=” @st ring/ det onat e_descr ipt
ion”>
</permi ssi on>
Example:
<mani festxml ns:andr oi d=" ht tp://schemas. andr oi d.
com/ apk/res/android"
package=" com. jav atpoi nt .hel l
o"
andr oid:v ersi onCode=" 1"
andr oid:v ersi onName=" 1. 0">
<uses- sdk
andr oi d:mi nSdkVer sion=" 8"
andr oi d:tar get SdkVer sion=" 15"/ >
<appl icat ion
andr oi d:icon=" @dr awabl e/ i
c_ l
auncher "
andr oi d:label =" @st ring/ app_ name"
andr oi d:theme=" @st y le/AppTheme">
<act ivity
andr oi d: name=" .Mai nAct ivit
y "
andr oi d: l
abel ="@st r i
ng/ ti
tle_act i
vity _mai n">
<intent -fil
ter>
<act ionandr oid: name=" andr oi
d. intent .
act i
on.MAIN"/ >
<cat egor yandr oid: name=" andr oid. i
ntent .
category.
LAUNCHER"/ >
</intent -fi
lter >
</act ivity >
</appl icat ion>
</mani fest >

21 MADMat
eri
al(
VL) MTDC:
PALAMANER
IntentFil
ter
IntentFi
lterarethecomponent swhichdeci
dethebehav iorofanint
ent.I
ntentf
il
ter
sspeci
fythetypeofint
ent
s
thatanAct iv
ity,serv
iceorBroadcastr
ecei
vercanrespondt o.I
tdeclar
esthefuncti
onal
i
tyofi
tsparent
component( i
.e.acti
vit
y,ser
vicesorbr
oadcastr
eceiver)
.Itdeclar
esthecapabil
i
tyofanyact
ivi
tyorserv
icesor
abr oadcastreceiver.
Syntax:
<acti
v i
tyandroid:name=" .MainActiv
ity">
<intent-f
il
terandr oi
d:icon="@dr awable/i
con"
android:l
abel="@string/label">
<actionandroid:name=" andr oi
d.i
ntent.
acti
on.MAIN"/>
<categoryandr oid:
name=" androi
d.i
ntent.
categor
y.LAUNCHER"/
>
</intent-
fil
ter
>
</acti
v i
ty>
Int
heabov esy nt
ax,
i
con:Thisisdisplayedasiconforact
ivi
ty.Youcancheckorsav epngi mageofnamei conindrawabl
efolder
.If
i
con image ofany ot hername i s stored please repl
ace @dr awable/i
con wit
ht hatimage name i.e.
@drawable/i
mage_ name.
l
abel:Thelabel/tit
lethatappear
sattopi nToolbarofthatpar
ticularAct
ivit
y.Youcancheckoreditl
abelname
by openi
ng St ri
ngXMLf i
le pr
esentinside Values folder(Values -> Stri
ngs)
.Replace @stri
ng/l
abelto
@stri
ng/yourl
abel.
Attri
butesofIntentFilt
er:
Belowar etheattr
ibutesofInt
entfi
lter
:
1.android:
icon
Ani conrepresent
st heacti
vit
y,serv
iceorbr
oadcastreceiv
erwhenauseri
nter
actwit
hitorwhenitappear
sto
userinanappl i
cati
on.Tosetani conyouneedtogiverefer
enceofdr
awabl
eresour
ceasdeclar
ed
andr
oid:
i
con="
@dr
awabl
e/i
con"
2.android:l
abel
Alabelrepresentstheti
tl
eofanact i
vi
tyont het
oolbar
.Youcanhavedif
ferentLabel
sf ordif
fer
entAct
ivi
ti
esas
peryourr equi
rementorchoice.Thelabelshoul
dbesetasar ef
erencetoast r
ingresource.However
,youcan
al
sousear awstringtosetalabelasdeclar
edinthebelowgi
vencodesnippet
andr
oid:
l
abel
="@st
ri
ng/
label
"
or
andr
oid:
l
abel
="NewAct
ivi
ty"

ElementsInIntentFi
lt
er:
Therearefol
lowingthreeel
ementsinanint
entf
il
ter
:
1.Act i
on
2.Dat a
3.Cat egory
1.Acti
on:
I
trepresentanactiv
iti
esact
ion,
whatanacti
vit
yisgoi
ngt
odo.I
tisdecl
aredwi
tht
henameat
tri
but
eas
giv
enbel ow
<act
ionandr
oid:
name="
str
ing"/
>
AnIntentFil
terel
ementmustcontai
noneormor
eacti
onel
ement
.Act
ioni
sastr
ingt
hatspeci
fi
est
he
acti
ont o perf
orm.Youcandecl ar
eyourownact
ionasgiv
enbelow.Butweusual
lyuseacti
on
constant
sdef i
nedbyI
ntentcl
ass.
2.Dat
a:
22 MADMat
eri
al(
VL) MTDC:
PALAMANER
Ther
earetwof ormsinwhi chyoucanpasst hedat
a,usi
ngURI(
Unif
orm ResourceI
dent
if
ier
s)orMI
ME
ty
peofdata.Forunder
standingtheconceptofURIi
nbett
ermannercheckthel
ink.
Thesynt
axofdataattr
ibuteisasfol
lows:
<dat
aandroid:
scheme=" stri
ng"
andr
oid:
host="
stri
ng"
andr
oid:
port="
str
ing"
andr
oid:
path="st
ri
ng"
andr
oid:
pathPatt
ern="stri
ng"
andr
oid:
pathPref
ix="
stri
ng"
andr
oid:
mimeTy pe="str
ing"/>
Thisspecif
iest heformatofdat aassoci
atedwithanIntentwhi
chyouusewithcomponent.As
expl
ainedinabov ecodesnippet
,dat
apassedt hr
oughI
ntentisaty
peofURI
.Checkt
hebelow giv
en
tabl
eforbettercl
ari
fi
cati
on
ACTI
ON DATA MEANI
NG
I
ntent
.ACTI
ON_
CALL t
el:
phone_
number Opensphoneappl
i
cat
ionandcal
l
sphonenumber

Opensphoneappl
i
cat
ionanddi
als(
butdoesn’
tcal
l
)
I
ntent
.ACTI
ON_
DIAL t
el:
phone_
number
phone_
number

Opensphoneappl
i
cat
ionanddi
als(
butdoesn’
tcal
l
)
I
ntent
.ACTI
ON_
DIAL v
oicemai
l
:
t
hev oi
cemail
number
.

I
ntent
.ACTI
ON_
VIEW geo:
l
at,
l
ong Openst
hemapsAppl
i
cat
ioncent
eredon(
lat
,long)
.

Opens the maps appl


i
cat
ion cent
ered on t
he
I
ntent
.ACTI
ON_
VIEW geo:
0,0?
q=addr
ess
speci
fi
edaddr
ess.

ht
tp:
//url Opens t
he br
owserappl
i
cat
ion t
othe speci
fi
ed
I
ntent
.ACTI
ON_
VIEW
ht
tps:
//url addr
ess.

Opens t
he browserappl
i
cat
ion and uses Googl
e
I
ntent
.ACTI
ON_
WEB_
SEARCH pl
ain_
text
sear
chforgi
venstri
ng
3.Cat
egory
:
Thisattr
ibut
eofIntentf i
l
terdict
atesthebehavi
orornatureofanInt
ent.Ther
eisast
ri
ngwhich
contai
nssomeaddi t
ionalinfor
mationaboutthei
ntentwhichwi
llbehandl
edbyacomponent
.The
synt
axofcategor
yisasf ol
lows:
<cat
egor
yandr
oid:
name="
str
ing"/
>
Most of I nt
ents do not r equi
re a cat egory f or example: CATEGORY_BROWSABLE,
CATEGORY_ LAUNCHER.
BROWSABLE– Br owsablecategory
,acti
vi
tyall
owsi t
selftobeopenedwi t
hwebbrowsertoopenthe
ref
erenceli
nkprovi
dedindata.
LAUNCHER–Launchercat egoryputsanactivi
tyont hetopofstack,whenev
erappl
icat
ionwi
llst
art
,
theacti
vi
tycontai
ningt
hiscategorywil
lbeopenedfir
st.
<i
ntent-f
il
ter>
<!
--Codeher e-
->
<categoryandroid:
name="
andr
oid.
int
ent
.cat
egor
y.LAUNCHER"/>
</i
ntent-
fil
ter>
<i
ntent-f
il
ter>
<!
--Codeher e-
->
<categoryandroid:
name="
andr
oid.
int
ent
.cat
egor
y.BROWSABLE"/>
</i
ntent-
fil
ter>
23 MADMat
eri
al(
VL) MTDC:
PALAMANER
I
ntentFi
lt
erExampl
e:
<?xml v ersi on=" 1.0"encodi ng=" utf-
8" ?>
<mani festxml ns: android="ht tp://schemas. andr oid.com/apk/r
es/androi
d"
package=" com. exampl e.andr oid.intent f
il
ter s">
<appl icat ion
andr oid: allowBackup=" true"
andr oid: i
con=" @mi pmap/ i
c_ launcher "
andr oid: l
abel ="@st ri
ng/ app_ name"
andr oid: suppor tsRt l
="tr
ue"
andr oid: theme=" @st yl
e/AppTheme" >
<act i
v i
tyandr oid:name=" .Mai nAct ivi
ty "
>
<i
nt ent -filter>
<act ionandr oid: name=" andr oid.i
nt ent .
act i
on. MAI N"/>
<cat egor yandr oi d:
name=" andr oid.i
nt ent.cat egory.LAUNCHER"/>
</intent -filter>
</act ivi
t y>
<act i
v i
tyandr oid:name=" .Mai n2Act ivity">
<i
nt ent -
f il
ter >
<act i
onandr oid:name=" com. exampl e.andr oid.i
ntent f
il
ter
s.Mai
n2Activ
ity
"/>
<cat egor yandr oid:name=" andr oid.i
nt ent.cat egory.DEFAULT"/>
</i
nt ent -fil
t er
>
</act ivi
t y>
</appl icat ion>
</mani fest >
Per
missi
ons
Appper
missi
onshel
psuppor
tuserpr
ivacybypr
otect
ingaccesst
othef
oll
owi
ng:
 Rest
ri
cteddat
a,suchassy
stem st
ateanduser
s'cont
acti
nfor
mat
ion
 Rest
ri
ctedact
ions,
suchasconnect
ingt
oapai
reddev
iceandr
ecor
dingaudi
o

Wor
kfl
owf
orusi
ngper
missi
ons

I
fyourappoffersfunct
ionali
tythatmi ghtrequi
reaccesstorestr
ict
eddataorrestr
ictedactions, determine
whetheryoucangettheinformationorper formtheacti
onswi t
houtneedi
ngtodecl arepermi ssions.Youcan
f
ulf
il
l manyusecasesiny ourapp, suchast aki
ngphotos,pausi
ngmedi apl
ayback,anddi splayingrelevantads,
wi
thoutneedingtodeclar
eanyper missions.

Fi
gur
e1i
l
lust
rat
est
hewor
kfl
owf
orusi
ngappper
missi
ons:

24 MADMat
eri
al(
VL) MTDC:
PALAMANER
Typesofper missi
ons
Androidcategori
zesper
missi
onsint
odif
fer
entty
pes,Eachpermissi
on'stypei
ndi
catest
hescopeofrest
ri
cted
datathatyourappcanaccess,andt
hescopeofrest
ri
ctedact
ionsthatyourappcanper
for
m, whent
hesy st
em
grant
sy ourappthatper
missi
on.
1.I
nst
all
-t
imeper
missi
ons,
2.Runt
imeper
missi
ons,
3.Speci
alper
missi
ons

 I
nst
all
-t
imeper
missi
ons:

I
nstall
-ti
meper missionsgivey ourappl imit
ed Fi
gure2.Theli
stofanapp'si
nst
all
-t
ime
accesstor est
ri
cteddat aorlety ourappper form per
missi
ons,whichappear
sinanappstor
e.
rest
ri
ctedact i
onsthatmi ni
mal lyaffectthesy st
em
orotherapps.Wheny oudecl areinstall
-t
ime
permissionsinyourapp, anappst orepresentsan
i
nstall
-ti
meper missionnoticetot heuserwhent hey
viewanapp' sdetai
lspage, asshowni nfigure2.
Thesy st
em automat ical
lygrantsy ourappt he
permissionswhent heuseri nstall
sy ourapp.

I
nst
all
-t
imepermissi
onscanbecl assi
fi
edi
nto
 Nor malper
missions
 Signatur
epermissions.
Nor
malpermissi
ons
Thesepermissionsall
owaccesstodataandact i
onsthatextendbeyondyourapp'
ssandboxbutpr
esentv
ery
l
it
tl
erisktotheuser '
spri
vacyandtheoperati
onofotherapps.
Thesystem assignsthenormalpr
otect
ionlevel
tonormal permi
ssions.

Si
gnat
ureper
missi
ons:
Thesystem gr
antsasignat
ureper
mi ssi
ontoanapponl
ywhent
heappi
ssi
gnedbyt
hesamecer
ti
fi
cat
east
he
apportheOSt hatdef
inest
hepermission.

Appl
icati
onsthatimpl
ementpr
ivi
l
egedservices,suchasautof
il
lorVPNservi
ces,
alsomakeuseofsignat
ure
per
mi ssi
ons.Theseappsr
equi
reser
vice-
bindingsignat
ureper
missionssot
hatonlyt
hesyst
em canbindtot
he
ser
vices.

 Runt
imeper
missi
ons
permissi
ons,
giv
ey ourappaddi
ti
onalaccessto
Runt
imeper
missi
ons,
alsoknownasdanger
ous rest
ri
cteddat
aorletyourappperf
ormrestri
cted
25 MADMat
eri
al(
VL) MTDC:
PALAMANER
acti
onsthatmor esubst anti
allyaff
ectthesy stem Fi
gure3.Thesyst
em per
missionpr
omptt
hat
andotherapps.Ther efore,youneedt or equest appearswheny
ourapprequestsar
unt
ime
runt
imeper mi ssi
onsi ny ourappbef or
ey oucan permissi
on.
accessther estri
cteddat aorper f
ormr est r
icted
acti
ons.Don' tassumet hatthesepermi ssionshav e
beenprev i
ouslygr anted—checkt hem and, if
needed,requestt hem bef or
eeachaccess.

Whenyourapprequest
sarunt
imepermi
ssi
on,
the
syst
em pr
esentsarunt
imeper
missi
onpr
ompt,as
showni
nf i
gure3.

Manyrunt
imeper
missionsaccesspr
ivat
euserdat
a,aspeci
alty
peofrest
ri
cteddatathati
ncludespot
ent
ial
l
y
sensi
ti
vei
nfor
mati
on.Examplesofpr
ivat
euserdat
aincl
udelocati
onandcontacti
nfor
mation.

Themicr
ophoneandcameraprovi
deaccesstopart
icul
arl
ysensi
ti
vei
nfor
mat
ion.Ther
efor
e,t
hesy
stem hel
ps
youexpl
ainwhyy
ourappaccessesthi
sinf
ormati
on.

Thesy
stem assi
gnst
hedanger
ouspr
otect
ionl
evel
tor
unt
imeper
missi
ons.

 Speci
alper
missi
ons:

Speci
al permissi
onscorrespondtopart
icul
arappoperat
ions.Onl
ytheplatf
orm andOEMscandef
inespeci
al
permissions.Addi
ti
onall
y, t
heplat
for
m andOEMsusual l
ydefinespeci
alpermi
ssionswhent
heywantto
prot
ectaccesst opart
icularl
ypowerf
ulacti
ons,suchasdrawingoverot
herapps.

TheSpeci
alappaccesspagei
nsystem set
ti
ngscontai
nsasetofuser
-t
oggl
eabl
eoper
ati
ons.Manyoft
hese
oper
ati
onsarei
mplementedasspeci
alpermissi
ons.

26 MADMat
eri
al(
VL) MTDC:
PALAMANER

You might also like