25
컨컨컨 컨컨컨컨컨 컨컨컨

컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

  • View
    221

  • Download
    4

Embed Size (px)

Citation preview

Page 1: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

컨텐트 프로바이더

박승제

Page 2: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

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

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

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
Page 6: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

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

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
Page 9: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

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

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

URI summary

Page 12: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

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
Page 14: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android
Page 15: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android
Page 16: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

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

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

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
Page 20: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android
Page 21: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android
Page 22: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android
Page 23: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android
Page 24: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android
Page 25: 컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android

Thanks for Mobile Programming Chap7 ma-terial written by hykim