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

Writing and Integrating a Content Provider

Now that we’ve examined the general structure of the simple video list application, and provided a way for clients to access our content provider, it’s time to look at how the application both implements and consumes the SimpleFinchVideoContentProvider.

Common Content Provider Tasks

In the following sections, we provide a high-level guide to tasks associated with writing a content provider. We then provide an introduction to Android MVC and finish with an explanation of the SimpleFinchVideoContentProvider code.

Extending ContentProvider

Applications extend the ContentProvider class to handle URIs that refer to a particular type of data, such as MMS messages, pictures, videos, and so forth. For example, for a content provider class that handled videos, the ContentProvider.insert method would insert data that described a video into a SQLite table with columns appropriate for that information, such as a title, description, and similar information.

Start writing your content provider by implementing the following two methods:

onCreate

This method provides a hook to allow your content provider to initialize itself. Any code you want to run just once, such as making a database connection, should reside in this method.

String getType(Uri uri)

This method, given a URI, returns the MIME type of the data that this content provider provides at the given URI. The URI comes from the client application interested in accessing the data.

You’ll continue to implement ...

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