A (175)

(Tuis.) #1
CHAPTER 14: Android Content Providers: Providing Data to Applications 515

Next, you will take a look at how the content:// area in Android OS is used to access these database
structures using a Content Provider URI. Fortunately, you are already comfortable with Uri objects,
so you have a head start!


Referencing a Content Provider: Content URI


If you want to be able to tell the Android OS what Content Provider you want to access, it is
important that you understand the concept of the Content URI. You have used Uri objects before,
so you are very familiar with the function they play in accurately referencing data (content) pathways
in Android apps. Content Providers have a specialized path format. Just like the Internet’s HyperText
Transfer Protocol has a special format, HTTP://, content also has a special format that is very similar
(and thus easy to remember), which is content://.


The complete URI for an Android Content Provider contained in a URI object will follow this data
path format:


content://Authority/Path/ID


Consider in the following (hypothetical) Hello Universe Contact Galaxy database content URI:


content://com.hellouniverse.galaxydatabase/galaxy/andromeda/12345


In this imaginary URI, com.hellouniverse.galaxydatabase is the Data Authority, galaxy/andromeda/
represents the Data Path, and 12345 represents the _ID key for the actual Data Record.


A Content URI will always contain four necessary parts: The schema to use, in this case, content://
as well as a data authority, an (optional) data path to the data, and the _ID of the data record that
you want to access.


Table 14-4. CalendarContract databases in the Android provider package and the type of data that they contain
Database.Table Interface Database Table Contents
CalendarContract.AttendeesColumns Columns (joined) from attendees database
CalendarContract.CalendarAlertsColumns Data used for calendar alerts function
CalendarContract.CalendarCacheColumns Data used for calendar cache function
CalendarContract.CalendarColumns Calendar columns that other URIs can query
CalendarContract.CalendarSyncColumns Generic columns for use by sync adapters
CalendarContract.ColorsColumns Data used for calendar colors function
CalendarContract.EventDaysColumns Data used for calendar event day function
CalendarContract.EventsColumns Columns (joined) from the events database
CalendarContract.ExtendedPropertiesColumns Data Used in Calendar Extended Properties
CalendarContract.RemindersColumns Data used for calendar reminders function
CalendarContract.SyncColumns Sync info columns used by other databases
Free download pdf