ContentProvider used to get data from central repository. Android application contains content provider to provide data to other applications.
you can also create your custom content provider to get data from database / sdcard / media etc.
Content providers create an abstraction layer between its repository of data and external application that are using data.
External Application can call Content Provider methods with the use of ContentResolver.
ContentResolver work as ContentProvider client object, with the use of Content Resolver object we can get data from Content Provider.
ContentProvider and ContentResolver (provider clients) used together to create a interface for data to handles inter-process communication and access data in secure way.
Content provider show data to content resolver as one or many tables that will show same as relational database.
Android provide number of content providers that store common data such as contact informations, calendar information, and media files etc.
You can see list of content provider, Check this link from Android developer site
Content Providers List
Also check this link :
Be Careful With Content Providers
Content Provider Workflow :
See Sql Like Table Structure :
ContentResolver ( Client object to Access ContentProvider ) :
An application get data from a content provider with a ContentResolver client object.
The ContentResolver provide the basic create, retrieve, update, and delete functions.
When application called ContentResolver method then identically-named method call in ContentProvider.
If you call getContentResolver().query method then ContentProvider query method called.
If you call getContentResolver().insert method then ContentProvider insert method called.
Most of developer familiar with sql queries because of that Android has made ContentResolver methods parameters like sql query.
ContentResolver parameter comparison with SQL Query
=> CONTENT_URI :
A content URI is a URI that identifies data in a provider, similar like table name in SQL Query.
A content URI is a URI that identifies data in a provider. Content URIs include the symbolic name of the entire provider (its authority) and a name that points to a table (a path). When you call a ContentResolver method to access a table in a provider, the content URI for the table is one of the arguments.
=> mProjection :
This parameter define which column data you want to fetch from table.
=> mSelectionClause :
This parameter selection criteria for rows fetching from table.
Its like condition after where clause in sql.
? mark means user defined mSelectionArgs value will come in place on ? mark.
This is same as
=> mSelectionArgs :
This parameter is user defined value that will pass in place of mSelectionClause ? mark.
=> mSortOrder :
This parameter specifies the order in which rows appear in the returned Cursor.
Its is same as ORDER BY col,col,… in SQL.
Content Provider Permissions :
A provider’s application can specify permissions that other applications must have in order to access the provider’s data.
If application read contact data from device then use this permission
To Better understand check this code to get first contact phone number by contact provider :