what is Android Content Provider

 what is Android Content Provider

Content providersstoreand retrievedata and make it accessible to all applications.
•They are the only way to share data across Android applications. There's no common storage area that all Android packages can access.
•Android ships with a number of content providers for common data types (audio, video, images, personal contact information, and so on).

ContentProvidersare a data layer providing data abstraction for its clients and centralizing storage and retrieval routines in a single place.
•A ContentProvidermay provide data to an Activity or Service in the same application’s space as well as an Activity or Service contained in other applications.
•A ContentProvidermay use any form of data storage mechanism available on the Android platform, including files, SQLitedatabases, or even a memory-based hash map if data persistence is not required.


The data model

Content providers expose their data as a simple table on a database model, where each rowis a record and each columnis data of a particular type and meaning.
•For example, information about people and their phone numbers might be exposed as follows:
 

URIs

Each content provider exposes a public URI that uniquely identifies its data set.
•A content provider that controls multiple data sets (multiple tables) exposes a separate URI for each one.
•All URIs for providers begin with the string "content://".
•Android defines CONTENT_URI constants for all the providers that come with the platform. For example
–android.provider.Contacts.Phones.CONTENT_URIandroid.provider.Contacts.Photos.CONTENT_URI
–android.provider.CallLog.Calls.CONTENT_URIandroid.provider.Calendar.CONTENT_URI
•The ContentResolvermethod takes an URI as its first argument. It's what identifies which provider the ContentResolvershould talk to and which table of the provider is being targeted.

Querying a Content Provider

•You need three pieces of information to query a content provider:
–The URI that identifies the provider
–The names of the data fields you want to receive
–The data types for those fields
•If you're querying a particular record, you also need the ID for that record.
•A query returns a Cursorobject that can move from record to record and column to column to read the contents of each field. It has specialized methods for reading each type of data.

0 comments: