Download presentation
Presentation is loading. Please wait.
1
컨텐트 프로바이더 박승제
2
Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android Browser Bookmark, history, … Contacts Address, tel number, … MediaStore Audio, image, video, … Settings Global system-level device preferences Make own content provider & share data
4
Content Provider Basics all content providers implement a common interface for 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
6
there’s just a single instance of each type of ContentProvider but, it can communicate with multiple ContentResolver objects in different applications and processes the interaction between processes is handled by the ContentResolver and ContentProvider classes
7
The data model Content providers expose their data as a simple table on a database model each row is a record each column is data of a particular type and meaning
9
The data model A query returns a Cursor object can move from record to record and column to column to read the contents of each field has specialized methods for reading each type of data methods moveToFirst() moveToNext() moveToPrevious() moveToPosition() getPosition isFirst(), isLast(), isBeforeFirst(), isAfterLast()
10
URIs Each content Provider exposes a public URI wrapped as a Uri object uniquely identifies its data set Android defines CONTENT_URI constants for all the providers that come with the platform android.provider.Contacts.Phones.CONTENT_URI android.provider.Contacts.Photos.CONTENT_URI android.CallLog.Calls.CONTENT_URI
11
URI summary
12
Making the query To query a content provider, you can use either the ContentResolover.query() or the Activity.managedQuery() method both methods take the same set of arguments both return a Cursor object
16
Content Provider usage Modifying data Application needs WRITE permission Adding new records Adding new values to existing records Updating existing records Deleting records
17
Content Provider usage Adding records Set up map of (key, value) pairs in a ContentValues object Call ContentResolver.insert(uri, contentValues) Returned URI: the URI of new (uri + ID) used to query or modify this record
18
Content Provider usage Updating records Call ContentResolver.update() Deleting records Call ContentResolver.delete() URI of a specific row or URI of the table (android.provider.Conctacts.People.CONTENT_URI)
25
Thanks for Mobile Programming Chap7 material written by hykim
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.