Tải bản đầy đủ (.pdf) (484 trang)

Near field communication with android cookbook vitor subtil

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.84 MB, 484 trang )



NearFieldCommunicationwithAndroid
Cookbook


TableofContents
NearFieldCommunicationwithAndroidCookbook
Credits
AbouttheAuthor
AbouttheReviewers
www.PacktPub.com
Supportfiles,eBooks,discountoffers,andmore
WhySubscribe?
FreeAccessforPacktaccountholders
Preface
Whatthisbookcovers
Whatyouneedforthisbook
Whothisbookisfor
Conventions
Readerfeedback
Customersupport
Downloadingtheexamplecode
Errata
Piracy
Questions
1.GettingStartedwithNFC
Introduction
RequestingNFCpermissions
Gettingready
Howtodoit…


Howitworks…
IndicatingthatyourappusesNFC
Howtodoit…
Howitworks…
Definingminimalrequirements


Howtodoit…
Howitworks…
VerifyingwhetherthedevicehasanNFCadapter
Howtodoit…
Howitworks…
There’smore…
DownloadingOpenNFCAndroidEdition
Gettingready
Howtodoit…
DownloadingOpenNFCSDKEdition
Howtodoit…
ConfiguringtheOpenNFCAndroidadd-onintoyourAndroidSDK
Gettingready
Howtodoit…
Howitworks…
ConfiguringanNFC-enabledtestingAVD
Gettingready
Howtodoit…
Howitworks…
There’smore…
ConfiguringtheConnectionCentertool
Gettingready
Howtodoit…

Howitworks…
Testingyourappalltogether
Gettingready
Howtodoit…
Howitworks…
2.DetectingaTag
Introduction
Understandingtheforegrounddispatchsystem


Howtodoit…
Howitworks…
Understandingthetagdispatchsystem
Howtodoit…
Howitworks…
VerifyingifyourappstartedbecauseofanNFCintent
Howtodoit…
Howitworks…
Filteringtagsbytheircontenttype
Howtodoit…
Howitworks…
Filteringtagsbytheircontenttypeprogrammatically
Howtodoit…
Howitworks…
Filteringtagsbytheirtechnology
Howtodoit…
Howitworks…
Filteringtagsbytheirtechnologyusingprograms
Howtodoit…
Howitworks…

FilteringURItags
Howtodoit…
Howitworks…
3.WritingTagContent
Introduction
WorkingwiththeNDEFrecord
Gettingready
Howtodoit…
Howitworks…
WritingaURI-formattedrecord
Howtodoit…


Howitworks…
Writingatext-formattedrecord
Howtodoit…
Howitworks…
UsingAndroidApplicationRecord
Howtodoit…
Howitworks…
Workingwithexternaltypes
Howtodoit…
Howitworks…
Workingwithcustommimes
Howtodoit…
Howitworks…
4.WritingTagContent–Real-lifeExamples
Introduction
Makingaphonecallwithonetap–Part1
Gettingready

Howtodoit…
Howitworks…
SendingapredefinedSMS–Part1
Howtodoit…
Howitworks…
Visitingourwebsite
Howtodoit…
Howitworks…
Leavinga(small)note–Part1
Howtodoit…
Howitworks…
5.ReadingTagContent
Introduction
ObtainingNDEFMessagefromIntent


Gettingready
Howtodoit…
Howitworks…
Gettingthedataoutofthemessage
Howtodoit…
Howitworks…
Readingatext-formattedrecord
Gettingready
Howtodoit…
Howitworks…
ReadingaURI-formattedrecord
Howtodoit…
Howitworks…
Readingexternaltypes

Howtodoit…
Howitworks…
Readingcustommimes
Howtodoit…
Howitworks…
6.ReadingTagContent–Real-lifeExamples
Introduction
Makingaphonecallwithonetap–Part2
Gettingready
Howtodoit…
Howitworks…
SendingapredefinedSMS–Part2
Gettingready
Howtodoit…
Howitworks…
Leavinga(small)note–Part2
Gettingready


Howtodoit…
Howitworks…
Gettingthetaginformation
Howtodoit…
Howitworks…
7.SharingContentacrossDevices
Introduction
Creatingabasicpeer-to-peerHelloWorldapplication
Gettingready
Howtodoit…
Howitworks…

Sendingtextstootherdevices
Howtodoit…
Howitworks…
SendingafriendinviteonFacebook
Gettingready
Howtodoit…
Howitworks…
Invitingafriendtoplayagame–Part1
Howtodoit…
Howitworks…
8.ErrorHandlingandContentValidation
Introduction
Handlingtag-writingerrors
Gettingready
Howtodoit…
Howitworks…
Handlingtag-readingerrors
Gettingready
Howtodoit…
Howitworks…


Testingthetagdataforintegrity
Gettingready
Howtodoit…
Howitworks…
9.ExtendingNFC
Introduction
Turningotheradapterson/off
Gettingready

Howtodoit…
Howitworks…
ConfiguringaWi-Finetwork
Howtodoit…
Howitworks…
StartingaWi-Fihotspot
Howtodoit…
Howitworks…
Invitingafriendtoplayagame–Part2
Howtodoit…
Howitworks…
ControllinghotelroomaccesswithArduinoandNFC–Part1
Howtodoit…
Howitworks…
ControllinghotelroomaccesswithArduinoandNFC–Part2
Gettingready
Howtodoit…
Howitworks…
10.Real-lifeExamples–NFCUtilities
Introduction
Creatingmulti-actiontags
Gettingready
Howtodoit…


Howitworks…
Choosingthebestformatforourdata
Howtodoit…
Howitworks…
Lockingtags

Howtodoit…
Howitworks…
Jokingwithafriend
Gettingready
Howtodoit…
Howitworks…
Index



NearFieldCommunicationwithAndroid
Cookbook



NearFieldCommunicationwithAndroid
Cookbook
Copyright©2014PacktPublishing
Allrightsreserved.Nopartofthisbookmaybereproduced,storedinaretrievalsystem,
ortransmittedinanyformorbyanymeans,withoutthepriorwrittenpermissionofthe
publisher,exceptinthecaseofbriefquotationsembeddedincriticalarticlesorreviews.
Everyefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyofthe
informationpresented.However,theinformationcontainedinthisbookissoldwithout
warranty,eitherexpressorimplied.Neithertheauthor,norPacktPublishing,andits
dealersanddistributorswillbeheldliableforanydamagescausedorallegedtobecaused
directlyorindirectlybythisbook.
PacktPublishinghasendeavoredtoprovidetrademarkinformationaboutallofthe
companiesandproductsmentionedinthisbookbytheappropriateuseofcapitals.
However,PacktPublishingcannotguaranteetheaccuracyofthisinformation.
Firstpublished:June2014

ProductionReference:1060614
PublishedbyPacktPublishingLtd.
LiveryPlace
35LiveryStreet
BirminghamB32PB,UK.
ISBN978-1-78328-965-3
www.packtpub.com
CoverImagebyRavajiBabu(<>)



Credits
Author
VitorSubtil
Reviewers
DionLoughry
MichaelRoland
CommissioningEditor
KunalParikh
AcquisitionEditor
RebeccaYoué
ContentDevelopmentEditors
AthiraLaji
RikshithShetty
TechnicalEditors
ShubhangiDhamgaye
NovinaKewalramani
PratikMore
PratishSoman
CopyEditors

AlishaAranha
MradulaHegde
AdithiShetty
ProjectCoordinator
WendellPalmer
Proofreaders
SimranBhogal
MariaGould
AmeeshaGreen
PaulHindle
Indexer
MariammalChettiyar


ProductionCoordinator
AdoniaJones
CoverWork
AdoniaJones



AbouttheAuthor
VitorSubtilhasbeenawebdevelopersince2009andhasbeenworkingwithASP.NET,
C#,Oracle,andFluentNhibernateinthedevelopmentofEnterpriseManagement
applications.HestartedusingMVCandSOAquiterecently.
HeiscurrentlypursuinghisfinalyeargraduatestudiesinComputerEngineering,where
hegotintroducedtotheNFCtechnologyandbecameafanthereafter.
HeisenthusiasticaboutnewtechnologiessuchasHTML5,CSS3,andAndroid.Heloves
usingtheJQueryframeworkforJavaScriptprogrammingandusesnewfeaturesof
HTML5suchasOfflineStorage,theHistoryAPI,andCanvas.Hiscurrentfocusison

developingAndroidapplications.
Iwouldliketothankmygirlfriend,Sandra,forallthetimeshespenthelpingmeandall
thatshedidformeinsomedifficultsituationsthatoccurredwhilewritingthisbook.This
bookwouldhavenotbeenpossiblewithouther.



AbouttheReviewers
DionLoughryhasbeenprofessionallyinvolvedintheITfieldfornearly20yearsnow.
Whilehehasbeenmanagingthesupportforendusersforthemostofhiscareer,hehas
alwaysstayedontopofcutting-edgetechnologyandinnovation.Hehasincorporatedthis
habitasmuchaspossibleintohispersonallifeandbusinessaswell.Agreatexampleof
thiswaswhenhefirstsawaPCin1980.Hemanagedtosaveandborrowenoughmoney
topurchaseoneatthattime.Inaddition,hequicklylearnedhowtoprogramintheBASIC
language.Hispassionliesinusingnewtechnologyattheworkplacetoimproveefficiency
aswellassimplifylifeingeneral.NFCtechnologyisthenextgreatleapthatprovidesa
simplifiedwayofsharingandobtaininginformation.HehasbeeninvolvedwiththeNFC
technologyforanumberofyears.HehasalwaysbeenafanofPalmTechnologyandhas
workedwithafewmembersoftheoriginalPalmdevelopmentteam.Heiscurrently
workingonmanyapplicationsforAndroidandWindowsdevices.Thisisagreatstepinto
theworldofunpluggedcomputingtechnologyandinformationsharing,whichhasgreat
potential,yetiswidelyuntapped.
MichaelRolandisaresearcherattheNFCResearchLab,Hagenberg(Universityof
AppliedSciences,UpperAustria).HismainresearchinterestsareNFC,security,and
Android.HeisthecreatorofNFCTagInfo,oneofthemostsuccessfulNFCdeveloper
toolsforAndroiddevices,andtheco-authorofthebookAnwendungenundTechnikvon
NearFieldCommunication(NFC),SpringerPublishing.HeholdsaBSc.andanMSc.
degreeinEmbeddedSystemsDesign(UniversityofAppliedSciences,UpperAustria,
2007and2009,respectively)andaPhD.(Dr.Techn.)degreeinComputerScience
(JohannesKeplerUniversityLinz,2013).




www.PacktPub.com


Supportfiles,eBooks,discountoffers,and
more
Youmightwanttovisitwww.PacktPub.comforsupportfilesanddownloadsrelatedto
yourbook.
DidyouknowthatPacktofferseBookversionsofeverybookpublished,withPDFand
ePubfilesavailable?YoucanupgradetotheeBookversionatwww.PacktPub.comandas
aprintbookcustomer,youareentitledtoadiscountontheeBookcopy.Getintouchwith
usat<>formoredetails.
Atwww.PacktPub.com,youcanalsoreadacollectionoffreetechnicalarticles,signup
forarangeoffreenewslettersandreceiveexclusivediscountsandoffersonPacktbooks
andeBooks.


DoyouneedinstantsolutionstoyourITquestions?PacktLibisPackt’sonlinedigital
booklibrary.Here,youcanaccess,readandsearchacrossPackt’sentirelibraryofbooks.


×