Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
AndroidProgramming
AStepByStepGuideforBeginners!
CreateYourOwnApps!
KevinLyn.
Copyright©2015byKevinLyn.
All rights reserved. No part of this publication may be reproduced, distributed, or
transmitted in any form or by any means, including photocopying, recording, or other
electronic or mechanical methods, without the prior written permission of the author,
except in the case of brief quotations embodied in critical reviews and certain other
noncommercialusespermittedbycopyrightlaw.
Disclaimer
While all attempts have been made to verify the information provided in this book, the
authordoesn’tassumeanyresponsibilityforerrors,omissions,orcontraryinterpretations
of the subject matter contained within. The information provided in this book is for
educationalandentertainmentpurposesonly.Thereaderisresponsibleforhisorher
ownactionsandtheauthordoesnotacceptanyresponsibilitiesforanyliabilitiesor
damages,realorperceived,resultingfromtheuseofthisinformation.
TableofContents
BookDescription
Introduction
Chapter1:Definition
Chapter2:BasicsofAndroidProgramming
HowtocreateaProject
RunningtheApplication
RunningtheAppontheEmulator
Chapter3:StructureofanAndroidApplication
Chapter4:UserInterfaceinAndroid
TypesofAndroidLayouts
AttributesofAndroidLayout
UserInterfacecontrolsinAndroid
HowtocreateUserInterfaceControls
Chapter5:EventHandlinginAndroid
UsinganAnonymousInnerClasstoRegisteranEventListener
UsinganActivityimplementsListenerInterfacetoRegisteranEventListener
Chapter6:AdvancedfeaturesinAndroid
Toasts
Normaltoasts
LocationBasedservicesinAndroid
GettingtheLocationAddressinAndroid
InstallationofGooglePlayservices
Creatingtheapp
SendingEmailinAndroid
SendingSMSinAndroid
MakingPhoneCalls
Androidcamera
Conclusion
BookDescription
This book is about android programming. Its emphasis is to guide programmers and
especially beginners, on how to develop amazing android apps. The book starts by
explainingwhatanandroidisanditsorigin.Thenextthingishowtogetstarted,including
settinguptheenvironmentreadyforprogramming,creatinganewandroidproject,andas
wellashowtorunanandroidapp,whetherontheemulatororonthephysicaldevice.
The components of an android project are also explained. Many features which can be
includedinanamazingandroidapp,havebeenexploredwithcodeexamples,onhowto
implementthem.Byreadingthisbookyouwilllearnwhattoastsareandhowtodevelop
them.
You will also learn how to implement notifications in android. Apps can also support
Bluetoothandtheuseofcameras.Youwilllearnhowtodevelopappswiththesefeatures.
Themainpurposeofmostofthesedevicesistofacilitatecommunicationbetweenparties.
This book will teach you to understand how to develop apps which supports calling,
sendingSMSandemail.Theseareallexplainedchronologicallyandinasimplemanner
forbetterunderstanding.Forfurtherexplanationpictureshavealsobeenused.s
Thefollowingtopicsareexploredindetail:
Definition
BasicsofAndroidProgramming
StructureofanAndroidApplication
UserInterfaceinAndroid
EventHandlinginAndroid
AdvancedFeaturesinAndroid:
Toasts
Notifications
LocationBasedServices
SendingEmail
SendingSMS
MakingPhoneCalls
AndroidCamera
AndroidBluetooth
Introduction
Theuseofdevicesrunningandroidoperatingsystemhasincreasedanditisstillshowing
potential for future growth. These devices range from mobile phones to tablets. This
explainstheneedfornumerousandroidapps,tosatisfythedifferentrequirementsofthe
usersofthesedevices.
Mostpeopleusingtheseappsviewthemascomplextodevelop.Howeverthisisnotthe
case.Withandroidprogrammingonecancreateamazingappsforhisowndevices.One
can also upload the apps on Google Play, from where other device users can download
them.
Android apps also pay well, since they are purchased at a high price. The demand for
androiddevelopersisontherise,andyouasprogrammerorpotentialprogrammershould
takeadvantageofthisfact.
Chapter1:
Definition
Android is an operating system which runs on mobile phones and tablets.The
operatingsystemisdesignedtoberunonmobiledeviceswithatouch
screen. Android programming is the kind of programming, whereby applications are
developedtoberunontheAndroidoperatingsystem.
Expert java developers find it easier to learn Android programming, since the complex
partofthisprogrammingisbasedonjava.Whathappensinandroidprogrammingisthat,
theprogrammercreatestheuserinterfaceusingXMLcoding.Toaddfunctionality,which
mostprogrammerstrytofindtougher,theyhavetousejava.
Thisclearlyexplainswhy,expertjavadeveloperswillalwaysfinditeasytoprogramin
android.ItisnotamustforyoutouseXMLtocreatetheuserinterface,butjavacanalso
be used for this purpose. The problem is that too much coding is needed, when the
interfaceiscreatedusingjava.
InXML,onecanalsodraganddropcomponents,asopposedtocodingfromscratch.This
wayisverysimple,especiallyforbeginners.Theprogrammercanalsoadjusthowthese
componentsarealignedonthescreen,soastoachievetheintendedalignment.
ByJuly2003,over1millionandroidAppshadbeencreated.Theyhadalsorecordedmore
than 25 million downloads. This clearly shows how device users have great need for
android Apps. Worldwide,the majority of mobile phones in use run android operating
systems.Thisshowshowwidethemarketforandroidappsisanditisstillgrowing.
Gettingstarted
Beforeyoucanstartprogramminginandroid,youneedtosetupthenecessarytoolsfirst.
Thefollowingaretheprerequisites:
1. JavaDevelopmentToolkit(JDK)/JavaRuntimeEnvironment(JRE)–Thesemust
beinstalled,beforeyouinstalltheIDE.If
youtrytoinstallanyoftheIDEsbeforeinstallingoneofthese,theinstallationwill
fail,somakesurethatyoudownloadandinstallthembeforehand.JDKand
JREservethesamepurposewhenitcomestoandroidprogramming,soyoucan
choosetodownloadandinstallanyofthem.Theyareavailableforfreedownload.
2. Developmenttool
Currently,Googleprovidestwocommonandroiddevelopmenttools.Thesearethe
AndroidStudioandAndroidDevelopmentTools(ADT).Androidstudioisbased
onIntelliJwhereastheADTisbasedonEclipse.
IfyouareajavadeveloperyoumighthavecomeacrosstheEclipse.Unlikethe
ADT,AndroidstudiosupportstheGradlebuildsystem,whichisanewtechnology
inAndroid.IfyouwanttoenjoythisfeaturetheninstalltheAndroidstudio.
Ifyoufinditeasiertoworkwitheclipse,youcandownloadtheADTbundle.This
comeswithbothEclipseandSDKtoolsinstalled,soafterextractingit,youcanget
started.YoucanalsodownloadtheeclipseonitsownandthendownloadtheSDK
tools.Thesecanthenbeintegrated.Ifyouexperienceanydifficultywhile
integratingthetwo,justlookuponlineformanualsonhowtodoit.
Chapter2:
BasicsofAndroidProgramming
Beforecreatingyourfirstappinandroid,youshouldlearnhowtocreateaprojectandhow
touseit.Note,thatinandroidanynewappthatyoucreatecomeswithasimple“Hello
World”.Thiscomesbydefaultsinceisbuiltin.
HowtocreateaProject
ForyoutobeabletocreateaprojectinAndroid,justfollowthestepsbelow:
1. Clickon“File”andselect“New”
2. Choose“Project”followedby“AndroidProject”.
Notethatafterthis,doingitthenexttimeitwillbeeasier,asshownbelow:
File->New->AndroidProject
Thereareoptionswhichneedtobefilledin.Theseareexplainedbelow:
ProjectName-thisisthenameoftheproject.Itsfirstlettermustbein
Uppercase.
BuildTarget-thisistheversionofandroidthatyouneedtouse.Youcan
choose2.2,sincemostdevicesworldwideusethis.
Applicationname-thisisthetitletobeshownonthetitlebarofthe
android,oncetheappisrunonanandroiddevice.
Packagename-nameitascom.company.project.Note,thateveryappon
yourdevicebelongstoadifferentanduniquepackage.
Createactivity-java’stop-levelclassname.
MinSDKversion-thisshouldmatchthebuildtarget.
RunningtheApplication
Aftercreatingtheproject,youmaynoticethatitcamewiththedefault“Helloworld”,as
anexample.Inthissectionyouwilllearnhowtorunitandobservetheoutput.
Youcanruntheapplicationonyourrealdevice,suchasamobilephoneoryoucanusethe
emulatorwhichisinbuiltwiththedevelopmentenvironment.Forthoseusingwindows
andwantingtoruntheapplicationonthephysicaldevice,youmustinstallthenecessary
driversbeforehand.
Afterinstallingthedrivers,youthenneedtosetupthedevicetobereadyforacceptingthe
applicationtoberunonit.ThisisdonebyturningonUSBdebuggingonthedevice,
whichisafeaturemadeavailableforusebythedevelopers.Ifyourdeviceisrunningthe
earlierversionsofandroid,youcanfinditin:
Settings->Applications->Development
Ifyourdeviceisrunningandroid4.0andabove,finditin:
Settings->Developeroptions
Devicesrunningandroidversion4.2andnewer,willhavetheDeveloperoptionshidden
bydefault.Thiscanbeenabledbynavigatingto:
Settings->Aboutphone.
Thenyoucantapseventimeson“Buildnumber”andyouwillfindtheDeveloperoptions
onthepreviousscreen.NowthatyouarethroughwiththesettingsyoucanrunyourApp.
Justclickon“Run”andselectthedeviceonthedialogthatwillappear.Lookattheoutput
onyourphysicaldevice.
RunningtheAppontheEmulator
WhetheryouareusingtheADTorAndroidstudio,youcanrunyourapplicationonthe
Emulator.YouonlyneedtosetuptheAVD(AndroidVirtualDevice)anditwillbedone.
TosetuptheAVDonEclipsenavigateasfollows:
Window>AndroidVirtualDeviceManager
InAndroidstudionavigateasfollows:
Tools>Android>AVDManager
NotethatitisbettertostarttheAVDbeforerunningtheapplication,sinceyoucansetitto
bethewayyouwantittobeintermsofsizeandappearance.Toruntheapplicationonthe
emulatorjustselecttheprojectandclickon“Run”.Selecttorunontheemulatorand
watchtheoutput.
Chapter3:
StructureofanAndroidApplication
Theandroidapplicationhasmanycomponents,allofwhichcanbefoundintheproject.
Theseareexplainedbelow:
1.src-bydefault,itcontainsaclassnamed“MainActivity.java”.The.javasourcefilesfor
yourprojectwillbecontainedinthisclass.
2.gen-the.Rfileiscontainedhere,andisresponsibleforthereferenceofyourproject’s
resources.
3.bin-thepackagefiles.apkarecontainedhere,andeverythingelseneededtorunthe
project.
4.res/drawable-hdpi-containsthedrawableobjectsoftheproject.
5.res/layout-thisfoldercontainsthe.XMLfilethatdefinesthelayoutofyourapplication.
6.res/values-hasnumerousresources,suchas,definitionsforcolorsandstrings.
7.AndroidManifest.xml-definesthecharacteristicsofyourapp.Italsodefineseach
elementcontainedintheapp.
Chapter4:
UserInterfaceinAndroid
Theuserinterfaceofandroidcanhaveanumberofcomponents,includingbuttons,text
fieldsandothers.TheGUIofandroidisdefinedintheXMLfile.Considerthecodeshown
below:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<TextViewandroid:id=”@+id/tv”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“atextview”/>
<Buttonandroid:id=”@+id/btn”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=”abutton”/>
<!—YoucanaddmoreGUIelementshere—>
</LinearLayout>
YoucanseeanexampleoftheXMLfileabove.Notethatwehavecreatedtwoelements,a
textviewandabutton.Wehavegiventhemanid,whichwillbeusedtoidentifythem.We
havealsosizedthemintheintendedway,wherebyusingthewrap_contentinthetwo
cases.
Itmeansthatnonewillspanthewholeofthedevice’sscreen.Thetexttoappearoneach
elementhasalsobeenspecified.WehaveusedLinearLayout.Wecanthenloadthelayout
resource.Thiscanbedoneontheapplicationcodeasshownbelow:
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
TypesofAndroidLayouts
Thepurposeofdifferentlayoutsinandroidistocreateadifferentlook,feelandviewof
thecreatedandroidapps.
1.LinearLayout-allthechildrenarearrangedinasingledirection,either
horizontallyorvertically.
2.TableLayout-viewsaregroupedintorowsandcolumns.
3.RelativeLayout-childviewsaredisplayedinrelativepositions.
4.FrameLayout-canbeusedtodisplayasingleviewonthescreen,sinceit
actsasaplaceholder.
5.AbsoluteLayout-withthislayout,youareabletospecifyexactlywherethe
childrenwillbelocated.
6.Gridview-itemsaredisplayedinascrollabletwo-dimensionalgrid.
7.ListView-usedtodisplayitemswhichcanscroll.
AttributesofAndroidLayout
1.android:layout_height-definesthelayout’sheight.
2.android:layout_width-definesthelayout’swidth.
3.android:id-thisistheidentifierofthecomponent.
4.android:layout_marginTop-thespaceabovethelayout.
5.android:layout_marginBottom-spaceatthebottomofthelayout.
6.android:layout_marginRight-spacetotherightofthelayout.
7.android:layout_marginLeft-thespacetotheleftofthelayout.
8.android:layout_gravity-defineshowthechildviewswillbepositioned.
9.android:layout_weight-definestheallocationofviewstotheextraspacein
thelayout.
Notethatifyouseteitherthewidthorheightoftheviewto“wrap_content”,itwillonly
sizeitselftofititscontent.Ifyousetitto“fill_parent”,itwillsizeitselfsoastobeofthe
samesizeastheparentview.Gravityisimportantinpositioningtheviewonthescreen.
Youshouldnotethatthesyntaxforcreatingtheidentityofanyviewis:
android:id=“@+id/btn”
Toinstantiateanobjectofthebuttoninthejavaclassfromthelayout,doas
follows:
Buttonbutton=(Button)findViewById(R.id.btn)
Thisalsoappliestotheotherelementsofthelayout.
UserInterfacecontrolsinAndroid
Theuserinterfaceinandroidcanbemadeofanumberofelements.Youcanuseanyof
themdependingonwhatyouwanttoachieve.Thesecontrolsincludethefollowing:
1.TextView-displaystexttousers.
2.EditText-displaysthetextbuttheuserisabletoeditit.
3.Button-apush-button.Theusercanclickorpresstogetanaction.
4.AutoCompleteTextView-displayseditabletextjustlikeEditText,butit
suggestssometextstoyouwhileyouaretyping.
5.ImageButton-youcanusethistodisplayanimage.
6.ToggleButton-ithasalightindicatorwhichcanbeturnedonoroff.
7.CheckBox-representschoiceswhicharenotmutually(??)exclusive.
8.ProgressBar-thisshowstheprogressofatask,especiallytheonerunningon
thebackground.
9.RadioButton-thiscanbeinacheckedoruncheckedstate.
10.Spinner-allowsuserstoselecttheirchoicefromadrop-downlist.
11.DatePicker-makesitpossibleforuserstoselectadate.
12.TimePicker-usersareabletoselecttimeineitherAM/PMor24hourformat.
HowtocreateUserInterfaceControls
CreationofanyuserinterfacecontrolinvolvesspecifyingitsID,size,positionandalsoif
possiblethetexttobedisplayedonthecontrol.Considerthecodeshownbelow:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<TextViewandroid:id=”@+id/tv”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“ThisisaTextView”/>
</LinearLayout>
WehavecreatedaTextviewandgivenittheid“tv”.Thiswillbesolelyusedtoidentifyit.
Withinthecodewehavecreated,wehavealsospecifieditswidthandheightto
“wrap_content”,meaningthatitwillstretchonlytofititscontents.Inourjavaclasswe
needtoinstantiatethisTextView.Thiswillbeachievedasfollows:
TextViewview=(TextView)findViewById(R.id.tv)
Wehavenowcreatedtheobject“view,”whichisanexampleoftheTextView“tv”.
HavingcreatedaTextViewandaButton,andbeinglearnedhowtoinstantiatethem,you
musthavebynowrealizedthattheprocessisverysimple.Thesameprocedureappliesto
createothercontrols.
Chapter5:
EventHandlinginAndroid
Theuserinterfacealoneinandroidisnotenough.Thereisaneedtoaddfunctionalityor
eventstoit.Anexampleisabutton.Weneedtospecifywhatthebuttonshoulddo,onceit
hasbeenclickedorpressed.Withandroidevents,thefollowingconceptsarevery
important:
1.EventListeners-thisistheobjectresponsibleforreceivingnotifications
wheneveraneventhappens.
2.EventListenersRegistration-eventregistrationoccurswhentheevent
handlerandtheeventlistenerareregistered.Whenevertheeventlistenerfiresan
event,thehandlerwillbecalled.
3.EventHandlers-thismethodisresponsiblefortherealhandlingoftheevent.
Forittowork,itmustberegisteredwiththeeventlistener.
UsinganAnonymousInnerClasstoRegisteranEvent
Listener
OpenyourIDEandcreateaproject.Modifytheactivity_main.xmltobeasfollows:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<Button
android:id=”@+id/btn1”
android:layout_height=“wrap_content”
android:layout_width=“match_parent”
android:text=“SmallFont”/>
<Button
android:id=”@+id/btn2”
android:layout_height=“wrap_content”
android:layout_width=“match_parent”
android:text=“LargeFont”/>
<TextView
android:id=”@+id/tv”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:capitalize=“characters”
android:text=“Helloworld!”/>
</LinearLayout>
TheclassMainActivity.javashouldbeasfollows:
importandroid.os.Bundle;
importandroid.view.View;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.widget.Button;
importandroid.widget.TextView;
publicclassMainActivityextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//–instantiatethebuttons–
Buttonb1=(Button)findViewById(R.id.btn1);
Buttonb2=(Button)findViewById(R.id.btn2);
//—registerthefirstbuttontotheclickevent–
b1.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
//–instantiatethetextview—
TextViewtxtv=(TextView)findViewById(R.id.tv);
//—altersizeoftext—
txtv.setTextSize(14);
}
});
//—registerthesecondbuttonandtheclickevent–
B2.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
//–instantiatethetextview—
TextViewtxtv=(TextView)findViewById(R.id.tv);
//—altersizeoftext—
txtv.setTextSize(24);
}
});
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
Theabovearethetwoclasseswhichyouneedtomodify.Theotherclasseswillbeintheir
correctstatebydefault.AfteryouhavepreparedyourAVDyoucannowrunyourproject.
Ifyouareusingthephysicaldevice,youwillbealright.Justopenoneoftheclassesofthe
projectandclickon“Run”.Thefollowingwillbedisplayed:
Thefirsttwoarethebuttonswiththetextwehavesetintheactivity_Main.xmlfile.The
lastpartshowstheTextView,withthetextwhichwehavealsospecifiedinthe
Activity_Main.xmlfile.NotethatthetextontheTextViewisnoteditable.Forthe
buttons’sizewesettheheightto“wrap_content”.
Thisexplainswhytheheightshaveonlystretchedtoaccommodatethetextdisplayedon
thebuttons.Inthecaseofthewidthwesetitto“match_parent”,andthus,theyare
stretchinguptotheendsofthescreenoftheemulator.Trytoclickanyofthebuttons,and
youwillnoticethatthesizeofthetextdisplayedonthetextview,willchangetosize14.
Thisappliestobothbuttons.
UsinganActivityimplementListenerInterfacetoRegister
anEventListener
InthismethodthesetOnClickListenerisused.Itismostsuitablewhenyourapplication
hasonlyasinglecontrol.Iftheapplicationhasnumerousones,additionalprogrammingis
neededforyoutodeterminethecontrolwhichtriggeredanevent.Thisisalsoeasy,asit
canbeachievedbyusingthe“case”statement.Usingourpreviousproject,justmodifythe
MainActivity.java,tobeasfollows:
importandroid.os.Bundle;
importandroid.view.Menu;
importandroid.app.Activity;
importandroid.view.View.OnClickListener;
importandroid.view.View;
importandroid.widget.TextView;
importandroid.widget.Button;
publicclassMainActivityextendsActivityimplementsOnClickListener{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//–instantiatethetwobuttons–
Buttonb1=(Button)findViewById(R.id.btn1);
Buttonb2=(Button)findViewById(R.id.btn2);
//—registerfirstbuttonandtheclickevent–
b1.setOnClickListener(this);
//—registersecondbuttonandtheclickevent–
b2.setOnClickListener(this);
}
//–ImplementingtheOnClickListenermethod
publicvoidonClick(Viewv){
if(v.getId()==R.id.btn1)
{
//–instantiatetheTextview—
TextViewtxtv=(TextView)findViewById(R.id.tv);
//—alterthesizeoftext—
txtv.setTextSize(14);
return;
}
if(v.getId()==R.id.btn2)
{
//–instantiatethetextview—
TextViewtxtv=(TextView)findViewById(R.id.tv);
//—alterthesizeofthetext—
txtv.setTextSize(24);
return;
}
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
YouhavenowlearnedhowtoregisteranEventListener.Thetwomethodsgivethesame
result,soyoucanchoosetousetheonewhichyoufindyourselfmostfamiliarwith.
Insteadofusingtheprevioustwomethods,youcanchoosetomakeworkeasierfor
yourself,achievingthisfromthelayoutfile,thatis,theActivity_Main.XML.The
MainActivity.javaclasswilllookasfollows:
importandroid.os.Bundle;
importandroid.view.Menu;
importandroid.app.Activity;
importandroid.widget.Button;
importandroid.view.View;
importandroid.widget.TextView;
publicclassMainActivityextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//–settheactionforthefirstbutton.
publicvoidsetSmall(Viewv){
//–instantiatethetextview
TextViewtxtv=(TextView)findViewById(R.id.tv);
//—alterthesizeofthetext—
txtv.setTextSize(14);
return;
}
//–implementtheeventforthesecondbutton.
publicvoidsetLarge(Viewv){
//–instantiatethetextview.—
TextViewtxtv=(TextView)findViewById(R.id.tv);
//—alterthesizeofthetext—
txtv.setTextSize(20);
return;
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
TheActivity_Main.xmlfileforthisclassshouldbemodifiedtothefollowing:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<Button
android:id=”@+id/btn1”
android:layout_height=“wrap_content”
android:layout_width=“match_parent”
android:text=“SmallFont”
android:onClick=“setSmall”/>
<Button
android:id=”@+id/btn2”
android:layout_height=“wrap_content”
android:layout_width=“match_parent”
android:text=“LargeFont”
android:onClick=“setLarge”/>
<TextView
android:id=”@+id/tv”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:capitalize=“characters”
android:text=“Helloworld!”/>
</LinearLayout>
Inthiscase,wehavespecifiedthehandlermethodviatheandroid:setOnClickattributein
thelayoutfile.
Chapter6:
AdvancedfeaturesinAndroid
Toasts
Theseareakindofviewwhichareusedtodisplaylittleinformationtotheuser.The
messageisdisplayedforashortperiodoftime,afterwhichthetoastdisappears.Agood
exampleiswhenadjustingthevolume.Thetoastisaimedatbeing,asmuchobstructive
aspossible,soastoinsistinthereadingaparticularmessage.Therearetwotypesof
toasts:
Normaltoasts.
Customtoasts.
Normaltoasts
Createanewprojectandcallit“ToastApp”.Modifythexmlfileoftheprojecttogetthe
following:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<Button
android:id=”@+id/btn”
android:text=“ShowToast”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
</LinearLayout>
ModifytheMainaActivity.javaclasstothefollowing:
importandroid.app.Activity;
importandroid.view.View;
importandroid.os.Bundle;
importandroid.widget.Button;
importandroid.view.View.OnClickListener;
importandroid.widget.Toast;
publicclassMainActivityextendsActivity{
privateButtonb;
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button)findViewById(R.id.btn);
b.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
Toast.makeText(getApplicationContext(),
“Buttonisclicked”,Toast.LENGTH_LONG).show();
}
});
}
}
Onceyouarefinished,justselectyourprojectandclickrun.Abuttonwillappearwritten
“ShowToast”.Clickonthisbuttonandyouwillgettheresultshownbelow:
Uponclickingthebutton,atextwritten“Buttonisclicked”willbeshown.Itwillappear
onthescreenforafewsecondsandthendisappear.Thisisanexampleofanormaltoast.
Customtoastview:
Thisisjustanadvancednormaltoastafterithasbeencustomized,maybebyaddingsome
imagesorotherfeaturestoit.Usingtheprojectabove,modifythexmlfiletothe
following:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:id=”@+id/advanced_toast”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“horizontal”
android:background=”#FFF”
android:padding=“5dp”>
<Button
android:id=”@+id/btn”
android:text=“ShowToast”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
<ImageView
android:layout_width=“wrap_content”
android:layout_height=“fill_parent”
android:id=”@+id/imgv”
android:layout_marginRight=“5dp”/>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“fill_parent”
android:id=”@+id/tv”
android:textColor=”#000”/>
</LinearLayout>
ModifytheMainActivity.javaclasstothefollowing:
importandroid.app.Activity;
importandroid.view.Gravity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.LayoutInflater;
importandroid.view.View.OnClickListener;
importandroid.view.ViewGroup;
importandroid.widget.ImageView;
importandroid.widget.Button;
importandroid.widget.Toast;
importandroid.widget.TextView;
publicclassMainActivityextendsActivity{
privateButtonb;
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button)findViewById(R.id.btn);
b.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
LayoutInflaterin=getLayoutInflater();
Viewly=in.inflate(R.layout.custom_toast,
(ViewGroup)findViewById(R.id.advanced_toast));
ImageViewiv=(ImageView)layout.findViewById(R.id.imgv);
iv.setImageResource(R.drawable.ic_launcher);
TextViewt=(TextView)layout.findViewById(R.id.tv);
t.setText(“Buttonisclicked!”);
Toasttst=newToast(getApplicationContext());
tst.setGravity(Gravity.CENTER_VERTICAL,0,0);
tst.setDuration(Toast.LENGTH_LONG);
tst.setView(ly);
tst.show();
}
});
}
}
Thecustomtoastmightbesomehowcomplex,butitisaveryniceone.Takenoteofthe
stepswehavefollowedrightuptotheend.Wehavesetadummyimageview.Thetoast
willalsobedisplayedforlonger,sincewehavesettheduration“tolong”.Uponrunning
theappandclickingthebutton,thefollowingoutputwillbeseen:
Thatisallabouttoasts.
Notifications
TheNotificationsclassisresponsibleforrepresentingnotificationsinandroid.The
NotificationManagerclassandgetSystemService()method,arealsoresponsibleforthe
creationofnotifications.Thesethreearecombinedasfollows:
NotificationManagernfnManager=(NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
TocreatetheNotificationobject,theNotification.Builderclassisused.Tospecifythe
actiontobeperformed,oncetheuserselectsthenotification,weusePendingIntent.
Createanxmlfilewiththefollowingcoding:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>
<Button
android:id=”@+id/btn”
android:text=“CreateNotification”>
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:onClick=“makeNotification”
</Button>
Createanotherxmlfilecalledlayout2.xmlandaddthefollowingcodetoit:
<?xmlversion=“1.0”encoding=“utf-8”?>
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“match_parent”>
<TextView
android:id=”@+id/tv1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“Activityopenedfromthenotification”>
</TextView>
</LinearLayout>
</LinearLayout>
CreateanotheractivitycalledReceiveActivityandregisteritwithAndroidManfest.mffile.
Addthefollowingcodetotheactivity:
importandroid.app.Activity;
importandroid.os.Bundle;
publicclassReceiveActivityextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.layout2);
}
}
Notethatintheactivityabove,wearereferringtothelayout2xmlfileratherthanthe
mainxmlfile.Modifytheactivityclasstothefollowing:
importandroid.app.Activity;
importandroid.app.NotificationManager;
importandroid.app.Notification;
importandroid.app.PendingIntent;
importandroid.content.Intent;
importandroid.view.View;
importandroid.os.Bundle;
publicclassNotificationActivityextendsActivity{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
publicvoidcreateNotification(Viewv){
Intentin=newIntent(this,ReceiveActivity.class);
PendingIntentpIn=PendingIntent.getActivity(this,0,in,0);
Notificationnt=newNotification.Builder(this)
setContentTitle(“Youhaveanmailfrom”+“example@gmail.com”)
setContentText(“Subject”).setSmallIcon(R.drawable.icon)
setContentIntent(pIn)
addAction(R.drawable.icon,“Call”,pIn)
addAction(R.drawable.icon,“More”,pIn)
addAction(R.drawable.icon,“Andmore”,pIn).build();
NotificationManagernfnManager=(NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
nt.flags|=Notification.FLAG_AUTO_CANCEL;
nfnManager.notify(0,nt);
}
}
Nowthatyouhavefinished,justselecttheprojectandclick“Run”.Watchtheoutput.A
notificationwillbeseen,tellingyouthatyouhaveanemailfromwhomyouhave
specifiedinthecode.
LocationBasedservicesinAndroid
Googleplayservicesmakeitpossibleforyoutouseandroidappstogetyourlocation.
ThislocationcanbeintermsoftheLongitude,Latitude,timestamp,velocity,altitudeand
bearing.Therearesomemethodsthatcanbeappliedtothelocationobject,toget
informationaboutlocation.Examplesofthesemethodsincludethefollowing:
1.floatdistanceTo(Locationdest)-givesthedistancebetweenthecurrent
locationandanotherlocation.
2.doublegetAltitude()-givestheheightabovesealevelinmeters,ifavailable.
3.floatgetBearing()-givesthebearingindegrees.
4.doublegetLAtitude()-givesthelatitudeindegrees.
5.DoublegetLongitude()-givesthelongitudeindegrees.
Thesearejustafewoftheavailablemethods,soyoucanexploretherestandlearnhowto
usethemincoding.
GettingtheLocationAddressinAndroid
TheGeocoder.getFromLocation()canbeusedtogiveboth,theLatitudeandthe
Longitude,oncewehavegottheLocationobject.Thismethodtakesalongtimebeforeit
displaystheresults,soitisadvisabletorunitinthebackgroundusingthemethod
doInBackground().Thisisbecauseofthesynchronousnatureoftheprocess.
InstallationofGooglePlayservices
Beforedevelopinganapptoenableyougettingintolocationaddress,Googleplay
servicesSDKneedtobeinstalled.Thiscanbeaccomplishedbythefollowingsimple
steps:
1.StarttheSDKmanager.IfyouareusingEclipse,clickonWindow->Android
SDKManager.
2.Oncelaunched,clickon“Extra”.Fromthepackagelistshown,searchfor
“GooglePlayServices”.Ifyoudon’tfindit,thenithasnotbeeninstalled.Installit.
3.OnEclipse,importitintotheworkspacebyclickingonFile>Import.
Finally,selectAndroid>ExistingAndroidCodeintoWorkspace.Browseto
<android-sdk>/extras/google/google_play_services/libproject/.Youwillbefinished
afterimportation.IfyouareusingAndroidstudio,copy:
<android-sdk>/extras/google/google_play_services/libproject/google-playservices_lib/whichisthelibraryprojecttothelocationofyourandroidprojects.
Creatingtheapp
Nowthatyouhavefollowedallthestepsabove,it’stimetocreatetheapp.Createanew
projectandgiveitaname.ThenextstepistoaddtheGoogleplayservicetotheproject.
Todothis,justselecttheprojectandrightclickonit.ChooseBuildPath>Configure
BuildPath>Android>Add.DoubleclickontheGoogle_play_service_libwhichwillbe
shown.
Modifytheclassactivity_main.xmltothefollowing:
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<Buttonandroid:id=”@+id/loc”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“GetLocation”/>
<Buttonandroid:id=”@+id/dscon”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“DisconnectService”/>
<Buttonandroid:id=”@+id/cnt”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“ConnectService”/>
<TextView
android:id=”@+id/locationLabel”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
<TextView
android:id=”@+id/labaddress”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
</LinearLayout>
ModifytheclassMainActivity.javatothefollowing:
importjava.util.List;
importjava.io.IOException;
importjava.util.Locale;
importcom.google.android.gms.common.GooglePlayServicesClient;
importcom.google.android.gms.common.ConnectionResult;
importcom.google.android.gms.location.LocationClient;
importandroid.location.Address;
importandroid.content.Context;
importandroid.os.AsyncTask;
importandroid.location.Geocoder;
importandroid.os.Bundle;
importandroid.location.Location;
importandroid.support.v4.app.FragmentActivity;
importandroid.util.Log;
importandroid.widget.Button;
importandroid.view.View;
importandroid.widget.Toast;
importandroid.widget.TextView;
publicclassMainActivityextendsFragmentActivityimplements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener
{
LocationClientmloc;
privateTextViewlabeladdress;
privateTextViewlabelloc;
privateButtonlocbtn;
privateButtondisbtn;
privateButtonconBtn;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
labelloc=(TextView)findViewById(R.id.locationlabel);
labeladdress=(TextView)findViewById(R.id.labaddress);
locbtn=(Button)findViewById(R.id.loc);
locbtn.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
displayCurrentLocation();
}
});
disbtn=(Button)findViewById(R.id.dscon);
disbtn.setOnClickListener(newV.OnClickListener(){
publicvoidonClick(Viewv){
mLoc.disconnect();
labelloc.setText(“youaredisconnected….”);
}
});
conbtn=(Button)findViewById(R.id.cnt);
conbtn.setOnClickListener(newV.OnClickListener(){
publicvoidonClick(Viewv){
mLoc.connect();
labelloc.setText(“youareconnected….”);
}
});
mLoc=newLocationClient(this,this,this);
}
@Override
protectedvoidonStart(){
super.onStart();
//Connectiontotheclient.
Loc.connect();
labelloc.setText(“youareconnected….”);
}
@Override
protectedvoidonStop(){
//Disconnectionfromtheclient.
mLoc.disconnect();
super.onStop();
labelloc.setText(“youaredisconnected….”);
}
@Override
publicvoidonConnected(Bundledatamb){
//Displaytheconnectionstatus
Toast.makeText(this,“Connected”,Toast.LENGTH_SHORT).show();
}
@Override
publicvoidonDisconnected(){
//showthestatusofconnection
Toast.makeText(this,“Trytoreconnect,youaredisconnected.”,
Toast.LENGTH_SHORT).show();
}
@Override
publicvoidonConnectionFailed(ConnectionResultconResult){
//showtheerrorcodeiffailureoccurs
Toast.makeText(this,“Failureinconnection:”+
conResult.getErrorCode(),
Toast.LENGTH_SHORT).show();
}
publicvoiddisplayCurrentLocation(){
//Getthelongitudeandlatitudeofthecurrentlocation
LocationcurrLoc=mLoc.getLastLocation();
Stringmessage=“CurrentLocation:”+
Double.toString(currLoc.getLatitude())+“,”+
Double.toString(currLoc.getLongitude());
//currentlocationwillbeshownonthescreen
labelloc.setText(message);
//Toshowcurrentaddressonthedevice’sscreen
(newGetAddressTask(this)).execute(currLoc);
}
/*
Thiswillgivetheaddressasperthecurrentlatitudeandlongitude.Itisasubclassof
AsyncTask
*/
privateclassGetAddressTaskextendsAsyncTask<Location,Void,String>{
Contextmc;
publicGetAddressTask(Contextc){
super();
mc=c;
}
/*
*theonPostExposurewilldisplaytheaddresswhenthetaskis*finished.
*/
@Override
protectedvoidonPostExecute(Stringa){
//showthecurrentaddressonthescreen
labaddress.setText(a);
}
@Override
protectedStringdoInBackground(Location…params){
Geocodergcoder=
newGeocoder(mc,Locale.getDefault());
//gettingthecurrentlocationfromtheinputtedparameterlist
Locationlc=params[0];
//Creatingalistforcontainingtheaddresses
List<Address>ads=null;
try{
ads=gcoder.getFromLocation(lc.getLatitude(),
lc.getLongitude(),1);
}catch(IOExceptione1){
Log.e(“LocationSampleActivity”,
“IOExceptioningetFromLocation()”);
e1.printStackTrace();
return(“IOExceptionoccurredingettingtheaddress”);
}catch(IllegalArgumentExceptione2){
//Errormessagetobepostedinthelog
StringerrorMessage=“Wrongarguments”+
Double.toString(lc.getLatitude())+
”,”+
Double.toString(lc.getLongitude())+
”alreadypassedtoaddressservice”;
Log.e(“LocationSampleActivity”,errorMessage);
e2.printStackTrace();
returnerrorString;
}
//Iftheaaddressisreturnedbythereversegeocode
if(ads!=null&&ads.size()>0){
//Obtainthefirstaddress
Addressa=ads.get(0);
/*
*Formattingthefirstlineoftheaddressifavailable
*/
StringaText=String.format(
“%s,%s,%s”,
//addingastreetaddressifitisavailable.
a.getMaxAddressLineIndex()>0?
a.getAddressLine(0):””,
//Acityisusuallythelocality
a.getLocality(),
//gettingtheaddresse’scountry
a.getCountryName());
//returningthevalueoftext
returnaText;
}else{
return“Didn’tfindanyaddress”;
}
}
}//AsyncTaskclass
}
Thestring.xmlfileshouldbemodifiedtothefollowing:
<?xmlversion=“1.0”encoding=“utf-8”?>
<resources>
<stringname=“app_name”>LocationBasedServicesDemo</string>
<stringname=“action_settings”>Settings</string>
<stringname=“hello_world”>Helloworld!</string>
<stringname=“loc”>GetLocation</string>
<stringname=“dscon”>DisconnectService</string>
<stringname=“cnt”>ConnectService</string>
</resources>
TheAndroidManifest.xmlfileshouldbemodifiedtothefollowing:
<?xmlversion=“1.0”encoding=“utf-8”?>
<manifestxmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.LocationBasedServicesDemo“
android:versionCode=“1”
android:versionName=“1.0”>
<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“17”/>
<uses-permission
android:name=“android.permission.ACCESS_COARSE_LOCATION”/>
<application
android:allowBackup=“true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”>
<activity
android:name=“com.example.LocationBasedServicesDemo.MainActivity”
android:label=”@string/app_name”>
<intent-filter>
<actionandroid:name=“android.intent.action.MAIN”/>
<categoryandroid:name=“android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
</application>
</manifest>
Thatiswhatitentailstoworkwithlocationbasedservicesinandroid.Themostimportant
thingistoinstalltheGoogleplayserviceSDKandtherestwillbeeasy.Itisbettertousea
realdevicewhenrunningtheaboveapp,sincetheemulatormaylackthenecessary
features.YourSDKshouldalsobeupdatedtothelatestversion,otherwiseyouwillget
errors.
SendingEmailinAndroid
Sometimes,youmightneedtosendanemailfromyourandroidapp.Usingyourdeviceto
gmail,yahoo,outlookorotheremailaccounts.Sincetheseareavailable,youdon’tneedto
createanemailclient.Youonlyneedtomakethisserviceavailableonyourapp.Intents
areusedforthispurpose.ATION_SENDisusedtolaunchthealreadyinstalledemail
clientonyourdevice.The“maito:“willthenbeusedtosendthemail.Youcanaddthe
TO,SUBJECT,CCandTEXTtoyouremailbeforesending.Otherextrafieldswhichcan
beaddedinclude:
1.EXTRA_BCC-thisstringholdsemailaddressthatitexpectedtobeblind
carboncopied.
2.EXTRA_EMAIL-thisstringholdstheemailaddressestowhichthemessage
shouldbedeliveredto.
3.EXTRA_CC-holdsemailsthatareexpectedtobecarboncopied.
4.EXTRA_SUBJECT-astringwhichholdsthesubjectlineofthemessage.
5.EXTRA_HTML_TEXT-suppliesthealternativetoEXTRA_TEXTin
HTMLformat.
6.EXTRA_TEXT-suppliesthedatatobesent.
Fromtheexamplebelow,youwilllearnhowtousetheIntentobjectforthepurposeof
launchingtheemailclientinstalledonyourdevice.Theemailwillbesenttogivenclients.
Runtheapponaphysicaldeviceratherthanontheemulator,sinceitmightlackthe
requiredfeatures.ThedeviceshouldhavethelatestOSversion.Anemailclientshouldbe
installedonyourdevice,example,Gmail.
Example:
Createanewprojectandgiveitthenameofyourchoice.Modifytheactivity_main.xml
filetothefollowing:
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<Buttonandroid:id=”@+id/email”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“ComposeEmail”/>
</LinearLayout>
Modifythejavaclass,MainActivity.javatothefollowing:
importandroid.os.Bundle;
importandroid.net.Uri;
importandroid.view.View;
importandroid.content.Intent;
importandroid.app.Activity;
importandroid.util.Log;
importandroid.widget.Button;
importandroid.view.Menu;
importandroid.widget.Toast;
publicclassMainActivityextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Buttonembtn=(Button)findViewById(R.id.email);
embtn.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewview){
composeandSendEmail();
}
});
}
protectedvoidcomposeandSendEmail(){
Log.i(“Sendemail”,””);
String[]TO={“mikeartemov@gmail.com”};
String[]CC={“test@gmail.com”};
IntenteIntent=newIntent(Intent.ACTION_SEND);
eIntent.setData(Uri.parse(“mailto:”));
eIntent.setType(“text/plain”);
eIntent.putExtra(Intent.EXTRA_EMAIL,TO);
eIntent.putExtra(Intent.EXTRA_CC,CC);
eIntent.putExtra(Intent.EXTRA_SUBJECT,“Addsubject”);
eIntent.putExtra(Intent.EXTRA_TEXT,“Addemailmessage”);
try{
startActivity(Intent.createChooser(eIntent,“Sendmail…”));
finish();
Log.i(“Emailhasbeensend…”,””);
}catch(android.content.ActivityNotFoundExceptionex){
Toast.makeText(MainActivity.this,
“Youhavenotinstalledemailclient.”,Toast.LENGTH_SHORT).show();
}
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Additemstotheactionmenuiftheyareavailable.
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
Modifythecontentsofthestring.xmlfiletothefollowing,todefineconstants:
<?xmlversion=“1.0”encoding=“utf-8”?>
<resources>
<stringname=“app_name”>AndroidSendingEmail</string>
<stringname=“hello_world”>Helloworld!</string>
<stringname=“action_settings”>Settings</string>
<stringname=“email”>ComposeEmail</string>
</resources>
NotethatnochangesshouldbemadetotheAndroidManifest.xmlfile,somaintainitonits
defaultstate.Youcannowrunyourappbyselectingtheprojectandclickingon“Run”
fromthetoolbar.Selecttoruntheappontherealdevicefromthedialogthatwillappear.
Thefollowingwindowshouldappear:
Clickonthe“ComposeEmail”button.Alltheemailclientsinstalledonyourdevicewill
beenlisted.Choosetheoneofyourchoice.Youwillthenseethefieldsforfillinginthe
“To”email,theSubject,andthenanotherfieldwhereyoucancomposeyourmessage.You
canthenhittheSendEmailbuttonandtheemailwillbesent.
SendingSMSinAndroid
Youmightneedtouseyourapptosendmessagestootherpeople.Thiscanbe
implementedintwoways:
1.BytheuseofSmsManager.
2.BytheuseofBuit-inIntent.
UsingSmsManager
Itmanagestheoperationsinvolvingthesendingofmessagestoothermobilephones.Itis
implementedasfollows:
SmsManagermanager=SmsManager.getDefault();
WehaveimplementeditbycallingthemethodSmsManager.getDefault(),whichisastatic
method.Theinstantiatedobjectabove,thatis,“manager”canthenbeusedtosend
messagestothespecifiedmobilenumberasshownbelow:
manager.sendTextMessage(“phoneNo”,null,“SMS”,null,null);
OthermethodswhichcanbeappliedtotheclassSmsManagerincludethefollowing:
1.ArrayList<String>messagedivision(Stringtext)-asinglemessageisdivided
intoseveralfragments.NofragmentisbiggerthantheoriginalSMSmessage.
2.staticSmsManagergetDefault()
ReturnstotheuserthedefaultinstanceofSmsManager.
ForyoutodemonstratesendingaSmstext,youneedaphysicaldevicerunningandroid.
otherwise,theemulatormightendupfailing.YoushouldalsotargetSDK.
Createanewprojectandgiveitanameofyourchoice.Modifytheactivity_main.xmlfile
tothefollowing:
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<TextView
android:id=”@+id/mobNo”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“EnterPhoneNumber:”/>
<EditText
android:id=”@+id/editmobNo”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:inputType=“phone”/>
<TextView
android:id=”@+id/tvMessage”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“EnterSMSMessage”/>
<EditText
android:id=”@+id/edSMS”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:inputType=“textMultiLine”/>
<Buttonandroid:id=”@+id/btnsendsms”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“SendSMS“/>
</LinearLayout>
ModifythejavaclassMainActivity,javatothefollowing:
importandroid.telephony.SmsManager;
importandroid.os.Bundle;
importandroid.view.Menu;
importandroid.app.Activity;
importandroid.util.Log;
importandroid.widget.Button;
importandroid.widget.Toast;
importandroid.view.View;
importandroid.widget.EditText;
publicclassMainActivityextendsActivity{
Buttonsbtn;
EditTextmobNo;
EditTextmsge;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sbtn=(Button)findViewById(R.id.btnsendsms);
mobNo=(EditText)findViewById(R.id.editmobNo);
msge=(EditText)findViewById(R.id.edSMS);
sbtn.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
sendMessage();
}
});
}
protectedvoidsendMessage(){
Log.i(“SendSMS”,””);
StringmobNo=mobNo.getText().toString();
Stringmessage=msge.getText().toString();
try{
SmsManagermanager=SmsManager.getDefault();
manager.sendTextMessage(mobNo,null,message,null,null);
Toast.makeText(getApplicationContext(),“SMSsent.”,
Toast.LENGTH_LONG).show();
}catch(Exceptione){
Toast.makeText(getApplicationContext(),
“sendingfailed,pleasetryagain.”,
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
TheAndroidManifest.xmlfileshouldbemodifiedtothefollowing:
<?xmlversion=“1.0”encoding=“utf-8”?>
<manifestxmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.sendsmstext”
android:versionCode=“1”
android:versionName=“1.0”>
<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“17”/>
<uses-permissionandroid:name=“android.permission.SEND_SMS”/>
<application
android:allowBackup=“true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”>
<activity
android:name=“com.example.sendsmstext.MainActivity”
android:label=”@string/app_name”>
<intent-filter>
<actionandroid:name=“android.intent.action.MAIN”/>
<categoryandroid:name=“android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
</application>
</manifest>
Nowthatyouarefinished,it’stimetoruntheapp.Justconnectthedevicetothecomputer
usingaUSBcable.Selecttheprojectoropenoneofitsfilesandclick“Run”fromthe
toolbar.Selecttoruntheapponthedevice.Thefollowingwillbeseen:
MakesurethatyourGSMconnectionisokay.Enterthephonenumberoftherecipient,
followedbytheSMSmessageitself.Finally,clickonthe“SendSMS”button.Your
messagewillbedelivered.
UsingBuilt-inIntent
Inthismethod,ACTION_VIEWisusedtolaunchtheSMSclientinstalledonyourdevice.
Intentintent=newIntent(Intent.ACTION_VIEW);
Smsto:andthetypeofdatatobesendshouldalsobespecified:
intent.setData(Uri.parse(“smsto:”));
intent.setType(“vnd.android-dir/mms-sms”);
Youcanthenspecifyboththephonenumberandmessageasfollows:
intent.putExtra(“address”,newString(“1123406889;3493694320”));
intent.putExtra(“sms_body”,“SMStoMike”);
Notethatintheaboveexample,wearesendingtheSMStotwonumbersandwehave
usedasemi-colon(;)toseparatethetwo.Boththe“address”andthe“sms_body”should
bewritteninlowercase,sincetheyarecasesensitive.
Example:
Createanewprojectandgiveitanameofyourchoice.Modifytheactivity_main.xmlfile
tothefollowing:
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<Buttonandroid:id=”@+id/smssend”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“ComposeSMS”/>
</LinearLayout>
ModifytheMainActivity.xmltothefollowing:
importandroid.app.Activity;
importandroid.net.Uri;
importandroid.util.Log;
importandroid.os.Bundle;
importandroid.content.Intent;
importandroid.view.View;
importandroid.view.Menu;
importandroid.widget.Toast;
importandroid.widget.Button;
publicclassMainActivityextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Buttonsbtn=(Button)findViewById(R.id.smssend);
sbtn.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
sendSMSText();
}
});
}
protectedvoidsendSMSText(){
Log.i(“SendSMS“,””);
Intentintent=newIntent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(“smsto:”));
smsIntent.setType(“vnd.android-dir/mms-sms”);
intent.putExtra(“address”,newString(“7825456929”));
intent.putExtra(“sms_body”,“SendSMStoMike”);
try{
startActivity(intent);
finish();
Log.i(“SMShasbeensent…”,””);
}catch(android.content.ActivityNotFoundExceptionex){
Toast.makeText(MainActivity.this,
“sendingSMShasfailed,tryagain.”,Toast.LENGTH_SHORT).show();
}
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//itemsareaddedtotheactionbariftheyareavailable.
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
TheNadroidManifest.xmlfileshouldbeasfollows:
<?xmlversion=“1.0”encoding=“utf-8”?>
<manifestxmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.sendsmstext”
android:versionCode=“1”
android:versionName=“1.0”>
<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“17”/>
<application
android:allowBackup=“true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”>
<activity
android:name=“com.example.sendsmstext.MainActivity”
android:label=”@string/app_name”>
<intent-filter>
<actionandroid:name=“android.intent.action.MAIN”/>
<categoryandroid:name=“android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
</application>
</manifest>
Onceyouhavefinished,connectyourphonetothecomputer,selecttheprojectandclick
“Run”.Choosetorunonthedevice.Thefollowingscreenwillappear:
Clickonthe“ComposeSMS”button.Youcanmodifythedefaultsthatwillappear.Once
youwritethemessageandthephonenumber,clickonsendandtheSMSwillbesent.
MakingPhoneCalls
Althoughyoucanstillmakeacallwithyourphonenumber,youmightneedtoinclude
thisinyourapp,whenneedingtocallusingahardcodednumber.Inthissection,youwill
learnhowtouseintenttomakeacall.Thecallfunctionalityistriggeredby
ACTION_CALL,soyoumustusetheintenttocallit.:
Intentintent=newIntent(Intent.ACTION_CALL);
YoucanuseACTION_DIAL,insteadoftheaboveACTION_CALL,ifyouwanttobe
abletomodifythenumbertobecalled.
Example:
Createanewprojectandgiveitanameofyourchoice.Modifytheactivity_main.xmlfile
tothefollowing:
<LinearLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“fill_parent”
android:layout_height=“fill_parent”
android:orientation=“vertical”>
<Buttonandroid:id=”@+id/call”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:text=“MakeCall”/>
</LinearLayout>
ModifytheclassMainActivity.javatothefollowing:
importandroid.app.Activity;
importandroid.net.Uri;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.util.Log;
importandroid.view.Menu;
importandroid.widget.Button;
importandroid.view.View;
importandroid.widget.Toast;
publicclassMainActivityextendsActivity{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Buttonbtn=(Button)findViewById(R.id.call);
btn.setOnClickListener(newView.OnClickListener(){
publicvoidonClick(Viewv){
phoneCall();
}
});
}
protectedvoidphoneCall(){
Log.i(“Makecall”,””);
Intentintent=newIntent(intent.ACTION_CALL);
intent.setData(Uri.parse(“tel:0123456789”));
try{
startActivity(intent);
finish();
Log.i(“callhasbeenmade…”,””);
}catch(android.content.ActivityNotFoundExceptionex){
Toast.makeText(MainActivity.this,
“failedtocall,tryagainlater.”,Toast.LENGTH_SHORT).show();
}
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Itemsareaddedtotheactionbarifavailable.
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
ThefollowingpermissionsshouldbeaddedtotheAndroidmanifest.xmlfile:
<?xmlversion=“1.0”encoding=“utf-8”?>
<manifestxmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.phonecallexample”
android:versionCode=“1”
android:versionName=“1.0”>
<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“17”/>
<uses-permissionandroid:name=“android.permission.CALL_PHONE”/>
<uses-permissionandroid:name=“android.permission.READ_PHONE_STATE”/>
<application
android:allowBackup=“true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”>
<activity
android:name=“com.example.phonecallexample.MainActivity”
android:label=”@string/app_name”>
<intent-filter>
<actionandroid:name=“android.intent.action.MAIN”/>
<categoryandroid:name=“android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
</application>
</manifest>
Nowconnectthedevicetoyourcomputer.Selecttheprojectandthenclickon“Run”.
Watchtheoutputonthedevice’sscreen.Abuttonwritten“Call0123456789”willbeseen.
Clickonitifyouwishtobeconnected,anditwillcallthemobilenumberabove.The
procedureisverysimple.
Androidcamera
Sometimes,youmightneedtheusersofyourapptousetheexistingandroidfromyour
app.Thisispossibletobeachieved.Todemonstratethis,createanewprojectandgiveita
nameofchoice.Modifythexmlfilemain_activity.xmltothefollowing:
<RelativeLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”.MainActivity”>
<ImageView
android:id=”@+id/iv1”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_marginLeft=“34dp”
android:layout_marginTop=“36dp”
android:contentDescription=“Helloworld!”
android:src=”@drawable/ic_launcher”/>
<TextView
android:id=”@+id/tv1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentTop=“true”
android:layout_alignRight=”@+id/iv1”
android:text=“Taptheimagetoopenthecamera”
android:textAppearance=”?android:attr/textAppearanceLarge”/>
</RelativeLayout>
ModifythejavaclassActivityMain.javatothefollowing:
importandroid.graphics.Bitmap;
importandroid.os.Bundle;
importandroid.content.Intent;
importandroid.view.Menu;
importandroid.app.Activity;
importandroid.view.View.OnClickListener;
importandroid.view.View;
importandroid.widget.ImageView;
publicclassMainActivityextendsActivity{
ImageViewimgf;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgf=(ImageView)findViewById(R.id.iv1);
imgf.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
open();
}
});
}
publicvoidopen(){
Intenti=newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,0);
}
@Override
protectedvoidonActivityResult(intreqCode,intresCode,Intentd){
super.onActivityResult(reqCode,resCode,d);
Bitmapbm=(Bitmap)d.getExtras().get(“d”);
imgf.setImageBitmap(bm);
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
TheAndroidManifext.xmlfileshouldbemodifiedtothefollowing:
<?xmlversion=“1.0”encoding=“utf-8”?>
<manifestxmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.cameraexample”
android:versionCode=“1”
android:versionName=“1.0”>
<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“17”/>
<application
android:allowBackup=“true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”>
<activity
android:name=“com.example.camera.MainActivity”
android:label=”@string/app_name”>
<intent-filter>
<actionandroid:name=“android.intent.action.MAIN”/>
<categoryandroid:name=“android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
</application>
</manifest>
Connectyourphysicaldevicerunningandroidtothecomputer.Selecttheprojectandclick
“Run”fromthetoolbar.Choose,toruntheapponthedevice.Thefollowingoutputwillbe
seen:
Tapontheimageandthecamerawillopen.Youcantakeanyphotousingtheopened
camera.Aftercapturingapicture,youwillbegiventheoptionofwhethertodiscardor
keepthepicture.
AndroidBluetooth
Theandroid’sBluetoothAdapterclass,makesitpossibletocreateappsthatcansharedata
andfileswirelessly.Letusdemonstratethis.
Createanewprojectandgiveitanameofyourchoice.Modifytheactivity_main.xmlfile
tothefollowing:
<RelativeLayoutxmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”.MainActivity”>
<ScrollView
android:id=”@+id/sv1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_alignParentBottom=“true”
android:layout_alignParentLeft=“true”
android:layout_alignParentRight=“true”
android:layout_alignParentTop=“true”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>
<TextView
android:id=”@+id/tv1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“Bluetooth”
android:textAppearance=”?android:attr/textAppearanceLarge”/>
<Button
android:id=”@+id/b1”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:onClick=“on”
android:text=“TurnOn”/>
<Button
android:id=”@+id/b2”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:onClick=“visible”
android:text=“GetVisible”/>
<Button
android:id=”@+id/b3”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:onClick=“list”
android:text=“ListDevices”/>
<Button
android:id=”@+id/b4”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:onClick=“off”
android:text=“TurnOff”/>
<ListView
android:id=”@+id/lv1”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:visibility=“visible”>
</ListView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
ModifytheMainActivity.javaclasstothefollowing:
importandroid.widget.Toast;
importjava.util.ArrayList;
importandroid.app.Activity;
importjava.util.List;
importjava.util.Set;
importandroid.os.Bundle;
importandroid.bluetooth.BluetoothAdapter;
importandroid.view.View;
importandroid.bluetooth.BluetoothDevice;
importandroid.view.Menu;
importandroid.content.Intent;
importandroid.widget.ListAdapter;
importandroid.widget.ArrayAdapter;
importandroid.widget.ListView;
importandroid.widget.Button;
publicclassMainActivityextendsActivity{
privateBluetoothAdapterbA;
privateButtonbOn,bOff,Visible,lst;
privateSet<BluetoothDevice>pairedDevices;
privateListViewlv;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bOn=(Button)findViewById(R.id.b1);
bOff=(Button)findViewById(R.id.b2);
Visible=(Button)findViewById(R.id.b3);
lst=(Button)findViewById(R.id.b4);
lv=(ListView)findViewById(R.id.lv1);
bA=BluetoothAdapter.getDefaultAdapter();
}
publicvoidon(Viewv){
if(!bA.isEnabled()){
IntenttOn=newIntent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(tOn,0);
Toast.makeText(getApplicationContext(),“Turnedon”
,Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(),“Alreadyon”,
Toast.LENGTH_LONG).show();
}
}
publicvoidlist(Viewv){
pairedDevices=bA.getBondedDevices();
ArrayListlst=newArrayList();
for(BluetoothDeviceb:pairedDevices)
lst.add(b.getName());
Toast.makeText(getApplicationContext(),“ShowingPairedDevices”,
Toast.LENGTH_SHORT).show();
finalArrayAdapteradpt=newArrayAdapter
(this,android.R.layout.simple_list_item_1,lst);
lv.setAdapter(adpt);
}
publicvoidoff(Viewv){
bA.disable();
Toast.makeText(getApplicationContext(),“Turnedoff”,
Toast.LENGTH_LONG).show();
}
publicvoidvisible(Viewv){
IntentgVisible=newIntent(BluetoothAdapter.
ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(gVisible,0);
}
@Override
publicbooleanonCreateOptionsMenu(Menumenu){
//Additemstotheactionbarifavailable
getMenuInflater().inflate(R.menu.main,menu);
returntrue;
}
}
ModifytheAndroidManifest.xmlfiletothefollowing:
<?xmlversion=“1.0”encoding=“utf-8”?>
<manifestxmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.bt”
android:versionCode=“1”
android:versionName=“1.0”>
<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“17”/>
<uses-permissionandroid:name=“android.permission.BLUETOOTH”/>
<uses-permissionandroid:name=“android.permission.BLUETOOTH_ADMIN”/>
<application
android:allowBackup=“true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme”>
<activity
android:name=“com.example.bt.MainActivity”
android:label=”@string/application_name”>
<intent-filter>
<actionandroid:name=“android.intent.action.MAIN”/>
<categoryandroid:name=“android.intent.category.LAUNCHER”/>
</intent-filter>
</activity>
</application>
</manifest>
Now,selecttheprojectandclick“Run”.Choosetorunonthephysicaldevice.The
followingscreenwillbedisplayed:
Clickonthe“TurnOn”button,andyouwillbeaskedtoverifywhetheryouwanttoturn
ontheBluetooth.
Acceptit.Clickonthe“GetVisible”buttonandyouwillalsobeaskedtoverify,whether
youwanttomakeyourdevicediscoverable.Thiswilltake120seconds:
Acceptthistoo.Clickonthe“ListDevices”button.Allpaireddeviceswillbedisplayed
ontheTextView.Byclickingthe“TurnOff”button,Bluetoothwillbeturnedoff.
Conclusion
Itcanbeconcluded,thatwithandroidprogrammingmuchcanbeachieved,bycreating
amazingapps.Androidprogramming,isbasedsolelyincreatingtheuserinterfaceby
usingXML,andjavaforaddingfunctionalitytoit.
Javacanalsobeusedtocreatetheuserinterfaceofanandroidapp,butmuchmorecoding
willbeneeded.AndroidappsdevelopmentcanbedoneonADT,whichreliesonEclipse,
oronAndroidstudio,whichisbasedonIntelliJ.Androidstudio,isthelatestdevelopment
environmentforandroid,anditsupportssomefeatureswhicharenotavailableinthe
ADT.
Inbothcases,onemustinstalltheJavaDevelopmentToolkit(JDk),ortheJavaRuntime
Environment(JRE),beforeinstallingtheIDEsabove.Aftersettingthemup,onecanthen
createamazingappsforhisowndevicesandalsoforsale.