Content Provider

Content provider is a mechanism provided by the Android platform to allow sharing information between applications, there is no common data area that the entire application stores the data separately and this data to external applications are shown in the form of one or more tables that are similar to the tables in a relational database. An application that wants all or part of the information it stores to be available for the rest of the system’s applications must provide a content provider through access to this information. Many of Android devices uses this mechanism to get information such as SMS list, the calendar, browser, callLog, settings, mediastore or contacts,
To retrieve data from a provider, your application needs “read access permission” for the provider. You can’t request this permission at runtime, but you must specify that you need this permission in your manifest using the . this mechanism allows to separate the application level of the data level. This means that we could access the data managed by these applications from our own Android applications using the corresponding content providers.

Our application has to get a way to internally store the information that we want to share. The common way to do it is a SQLite Base Data, because it initially is private, it is implement inside of an application and this is only accessible for the own application. but we have different means to do it, such as saving in a text file, XML file, online. Also it works like a database, with the methods insert(), update(), delete() and query(). The content provider will be the mechanism that allows us to publish this data to third parties through a standardized interface.

The ContentResolver methods provide the basic functions “CRUD”, The ContentResolver object analyzes the authority of the URI and uses it to “resolve” the provider by comparing the authority with a system table of known providers. The ContentResolver can then send the arguments of the query to the correct provider. To query a content provider, you specify the query string in the form of a URI which has following format:


  • The prefix is always content://
  • Authority: This specifies the name of the content provider
  • DataType: This indicates the type of data that this particular provider provides.
  • Id: This specifies the specific record requested.

Create a Content Provider:

  • Create a Content Provider Class that extends from ContentProviderBaseclass.
  • Define your content provider URI address
  • Create your own database, usually android uses SQLite.
  • Implement Content Provider queries to perform different databases.
  • Finally declare the new ContentProvider class in the Android Manifest.