Stored procedures

Each content provider on a device registers itself like a web site with a string (akin to a domain name) and a set of URIs. Here are two examples of providers registered in AndroidManifest.xml:

<provider android:name="SomeProvider"

android:authorities="com.your-company.SomeProvider" />

<provider android:name="NotePadProvider"

android:authorities="com.google.provider.NotePad"

An authority is like a domain name for that content provider. Given the preceding authority registration, these providers will honor URLs starting with that authority prefix:

content://com.your-company.SomeProvider/ content://com.google.provider.NotePad/

Content providers also provide REST-like URLs to retrieve or manipulate data. For the preceding registration, the URI to identify a directory or a collection of notes in the NotePadProvider database is content://com.google.provider.NotePad/Notes

The URL to identify a specific note is content://com.google.provider.NotePad/Notes/#

where # is the id of a particular note. Here are some additional examples of URIs that some data providers accept:

content://media/internal/images content://media/external/images content://contacts/people/ content://contacts/people/23

Content providers exhibit characteristics of web services as well. A content provider, through its URIs, exposes internal data as a service. But the output from the URL of a content provider is not typed data, as is the case for a SOAP-based web-service call. Nor do the content provider's URIs define the structure of the data that they return. But as you will see in this chapter's "Structure of Android MIME Types" section, a content provider has a built-in mechanism to determine the Multipurpose Internet Mail Extensions (MIME) type of the data represented by this URI. In short, the content provider has an ability to receive inputs via the URI and return outputs as a set of columns and rows, but it does not have a Web Service Definition Language (WSDL). The caller is expected to know the structure of the rows and columns that are returned.

In addition to resembling web sites, REST, and web services, a content provider's URIs also resemble the names of stored procedures in a database. Stored procedures present service-based access to the underlying relational data. URIs are similar to stored procedures because URI calls against a content provider return a cursor. However, content providers differ from stored procedures in that the input to a service call in a content provider is typically embedded in the URI itself.

We've provided these comparisons to give you an idea of the broader scope of content providers and their limitations.

0 0

Post a comment