Chapter 5. Content Providers
5.1. Introduction: Content Providers
The content provider is one of Android’s more clever ideas. It allows totally unrelated applications to share data, which is usually stored in an SQLite database, without prior arrangement, knowing only the names of the tables and fields in the data.
One widely used content provider is the Android Contacts provider. The first recipe in this chapter shows how easy it is to make an initial selection of data (this is done using an intent, as you might guess, but it returns a URI, not the actual data). You then drill down using an SQLite cursor or two.
Then we have a recipe that shows you how to create your own content provider. Again as you might expect, “there’s an interface for that.”
Finally, while it’s not directly related to content providers, Android also offers a more general remote procedure mechanism layered on AIDL (the Android Interface Definition Language), and the recipe for that is at the end of this chapter because it’s a similar topic.
5.2. Retrieving Data from a Content Provider
You want to read from a content provider such as Contacts.
PICK URI, open it in an intent
the URI from the returned intent, use
Activity.getContentProvider(), and process the data using SQLite
This is part of the contact selection code from TabbyText, my SMS text message sender for WiFi-Only Honeycomb tablets (the rest ...