컨텐트 프로바이더 박승제. content provider the only way to share data across applications...
Post on 21-Dec-2015
221 views
TRANSCRIPT
![Page 1: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/1.jpg)
컨텐트 프로바이더
박승제
![Page 2: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/2.jpg)
Content Provider
The only way to share data across applications
Using content providerUse existing content providers supplied by android
BrowserBookmark, history, …
ContactsAddress, tel number, …
MediaStoreAudio, image, video, …
SettingsGlobal system-level device preferences
Make own content provider & share data
![Page 3: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/3.jpg)
you can query these providers
for the data they contain
![Page 4: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/4.jpg)
Content Provider Basics
all content providers implement a common inter-facefor querying the provider and returning results
it’s an interface that client use indirectly,most generally through ContentResolver objects
you can use the ContentResolver’s methods to interact with whatever content providers you’re interested in
![Page 5: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/5.jpg)
![Page 6: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/6.jpg)
there’s just a single instance of each type of Con-tentProvider
but, it can communicate with multiple ContentRe-solver objects in different applications and pro-cesses
the interaction between processes is handled by the ContentResolver and ContentProvider classes
![Page 7: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/7.jpg)
The data model
Content providers expose their data as a simple tableon a database model
each row is a recordeach column is data of a particular type and meaning
![Page 8: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/8.jpg)
![Page 9: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/9.jpg)
The data model
A query returns a Cursor objectcan move from record to record and column to columnto read the contents of each fieldhas specialized methods for reading each type of datamethods
moveToFirst()moveToNext()moveToPrevious()moveToPosition()getPositionisFirst(), isLast(), isBeforeFirst(), isAfterLast()
![Page 10: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/10.jpg)
URIs
Each content Provider exposes a public URIwrapped as a Uri objectuniquely identifies its data set
Android defines CONTENT_URI constants for all the providers that come with the platform
android.provider.Contacts.Phones.CONTENT_URIandroid.provider.Contacts.Photos.CONTENT_URIandroid.CallLog.Calls.CONTENT_URI
![Page 11: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/11.jpg)
URI summary
![Page 12: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/12.jpg)
Making the query
To query a content provider, you can use either the ContentResolover.query() orthe Activity.managedQuery() method
both methods take the same set of argumentsboth return a Cursor object
![Page 13: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/13.jpg)
![Page 14: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/14.jpg)
![Page 15: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/15.jpg)
![Page 16: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/16.jpg)
Content Provider usage
Modifying dataApplication needs WRITE permission
Adding new recordsAdding new values to existing recordsUpdating existing recordsDeleting records
![Page 17: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/17.jpg)
Content Provider usage
Adding recordsSet up map of (key, value) pairs in a ContentValues ob-jectCall ContentResolver.insert(uri, contentValues)Returned URI: the URI of new (uri + ID)
used to query or modify this record
![Page 18: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/18.jpg)
Content Provider usage
Updating recordsCall ContentResolver.update()
Deleting recordsCall ContentResolver.delete()
URI of a specific rowor URI of the table (android.provider.Conctacts.People.CONTENT_URI)
![Page 19: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/19.jpg)
![Page 20: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/20.jpg)
![Page 21: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/21.jpg)
![Page 22: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/22.jpg)
![Page 23: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/23.jpg)
![Page 24: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/24.jpg)
![Page 25: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android](https://reader035.vdocuments.net/reader035/viewer/2022062516/56649d5a5503460f94a3a380/html5/thumbnails/25.jpg)
Thanks for Mobile Programming Chap7 ma-terial written by hykim