Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Using and Implementing Content Providers in Android

Although Android ships with several useful content providers, you can easily extend it and build your own.


advertisement
y previous Android article showed how to store data from Android using a SQLite database. Storing your data in a database is one good way to persist your data, but there's a caveat in Android—databases created in Android are visible only to the application that created them. That is to say, a SQLite database created on Android by one application is usable only by that application, not by other applications.

So, if you need to share data between applications, you need to use the content provider model as recommended in Android. This article presents the basics of content providers and how you can implement one.

 


Visit the Android Dev Center

 

Using a Content Provider

In Android, a content provider is a specialized type of data store that exposes standardized ways to retrieve and manipulate the stored data. Android ships with several useful content providers, as shown in Table 1.

Table 1. Android Content Providers: Here are some of Android's most useful built-in content providers, along with a description of the type of data they're intended to store.
Content Provider Intended Data
Browser Browser bookmarks, browser history, etc.
CallLog Missed calls, call details, etc.
Contacts Contact details
MediaStore Media files such as audio, video and images
Settings Device settings and preferences

To query a content provider, you provide a query string in the form of a URI, with an optional specifier for a particular row, using the following syntax:



<standard_prefix>://<authority>/<data_path>/<id>

For example, to retrieve all the bookmarks stored by your web browsers (in Android), you would use the following content URI:

content://browser/bookmarks

Similarly, to retrieve all the contacts stored by the Contacts application, the URI would look like this:

content://contacts/people

To retrieve a particular contact, you can specify the URI with a specific ID:

content://contacts/people/3

Of course, you can access all this information programmatically as well. The rest of this article walks you through the process.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap