O'Reilly logo

Programming Android by Zigurd Mednieks, G. Blake Meike, Masumi Nakamura, Laird Dornin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining a Provider Public API

Though we saw in Chapter 3 how clients use content providers, we provide more information here for content provider authors to fully implement the provider public API. For clients to use your content provider, you will need to create a public API class that contains a set of constants that clients use to access column fields of Cursor objects returned by your provider’s query method. This class will also define the content provider authority URI that provides the foundation of the whole provider URI communication scheme. Our class, FinchVideo.SimpleVideos, provides the API to our SimpleFinchVideo.

First we’ll explain the class in pieces, providing background on its fields, and then we’ll show a full listing.

Defining the CONTENT_URI

For a client application to query content provider data, it needs to pass a URI that identifies relevant data to one of the Android content resolver’s data access methods. These methods, query, insert, update, and delete, mirror the methods found on a content resolver that we define in Writing and Integrating a Content Provider. On receiving such an invocation, the content resolver will use an authority string to match the incoming URI with the CONTENT_URI of each content provider it knows about to find the right provider for the client. Thus, the CONTENT_URI defines the type of URIs your content provider can process.

A CONTENT_URI consists of these parts:

content://

A prefix that tells the Android Framework that it must find ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required