Intro to ContentProviders
The Android operating system uses content providers to facilitate access to shared data such as media files, contacts and calendar information. This article introduces the ContentProvider class, and provides two examples of how to use it.
Content Providers Overview
A ContentProvider encapsulates a data repository and provides an API to access
it. The provider exists as part of an Android application that usually also
provides a UI for displaying/managing the data. The key benefit of using a content
provider is enabling other applications to easily access the encapsulated
data using a provider client object (called a ContentResolver). Together, a content
provider and content resolver offer a consistent inter-application API for data
access that is simple to build and consume. Any application can choose to use
ContentProviders
to manage data internally and also to expose it to other applications.
A ContentProvider
is also required for your application to provide
custom search suggestions, or if you want to provide the ability to
copy complex data from your application to paste into other
applications. This document shows how to access and build
ContentProviders
with Xamarin.Android.
The structure of this section is as follows:
How it works – An overview of what the
ContentProvider
is designed for and how it works.Consuming a Content Provider – An example accessing the Contacts list.
Using ContentProvider to share data – Writing and consuming a
ContentProvider
in the same application.
ContentProviders
and the cursors that operate on their data are often
used to populate ListViews. Refer to the
ListViews and Adapters guide
for more information on how to use those classes.
ContentProviders
exposed by Android (or other applications) are an
easy way to include data from other sources in your application. They
allow you to access and present data such as the Contacts list, photos
or calendar events from within your application, and let the user
interact with that data.
Custom ContentProviders
are a convenient way to package your data for
use inside your own app, or for use by other applications (including
special uses like custom search and copy/paste).
The topics in this section provide some simple examples of consuming
and writing ContentProvider
code.