Unit - 6 Exploring Android’s Content Providers

Lesson Plan: Unit - 06
Subject: P15A2AAD - Android Application Development
Topic of Study: Exploring Android’s Content Providers
Grade/Level: Master of Computer Applications
Objective: Understand the component of Android’s Content Providers
Time Allotment: 55 Minutes


  • Exploring Androids Content Providers
    • A content provider manages access to a central repository of data.
    • Content providers can provide a way to share data with other apps.
    • Content providers are the standard interface that connects data in one process with code running in another process.
      • Exa.
    • Advantages of content providers:
      • Content providers offer granular control over the permissions for accessing data.
      • You can use a content provider to abstract away the details for accessing different data sources in your application
    • Accessing a provider:
      • Content providers are Android’s central mechanism that enables you to access data of other applications – mostly information stored in databases or flat files.
      • Content providers support the four basic operations, normally called CRUD-operations. 
      • Android provides some standard content providers to access contacts, media files, preferences and so on.
      • When you want to access data in a content provider, you use the ContentResolver object in your application's Context to communicate with the provider as a client.
      • The provider object receives data requests from clients, performs the requested action, and returns the results.
      • The ContentResolver methods provide the basic "CRUD" (Create, Retrieve, Update, and Delete) functions of persistent storage. 
    • Content URIs:
      • 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). 
      • The ContentProvider uses the path part of the content URI to choose the table to access.
      • Exa.
      • Whenever you want to access data from a content provider you have to specify a URI. 
      • URIs for content providers look like this: content://authority/optionalPath/optionalId
      • They contain four parts:
        • The scheme for content providers is always “content”.
        • Authorities have to be unique for every content provider. 
        • The optional path, is used to distinguish the kinds of data your content provider offers.
        • The id is used whenever you want to access a single record.
    • Types of URIs:
      • There are two types of URIs: 
        • Directory and Id-based URIs.
        • Note: If no id is specified a URI is automatically a directory-based URI.
        • You use directory-based URIs to access multiple elements of the same type (e.g. all songs of a band).
          • All CRUD-operations are possible with directory-based URIs.
        • You use id-based URIs if you want to access a specific element. 
          • You cannot create objects using an id-based URI – but reading, updating and deleting is possible.
    • Content Types:
      • A content type consist of a media type and a subtype divided by a slash. 
        • Exa. “image/png”. 
      • The media type “image” describes as an image file which is further specified by the subtype “png”.
  • Useful Built-in Android Content Provider:
    • Applications can access data within other applications on the Android system through content provider interfaces.
    • Android devices ship with a number of built-in applications, many of which expose their data as content providers.
    • Your application can access content provider data from a variety of sources.
    • You can find the content providers included with Android in the package android.provider.
    • Example:
      • 1. MediaStore
      • 2. CallLog
      • 3. Browser
      • 4. ContactsContract
      • 5. Settings
      • 6. UserDictionary
    • Figure.
    • Using the MediaStoreContent Provider:
      • You can use the MediaStore content provider to access media on the phone and on external storage devices.
      • The primary types of media that you can access are audio, images, and video.
      • You can access these different types of media through their respective content provider classes under android.provider.MediaStore.
      • You can retrieve, add, and delete media files from the device.
      • Exa.
    • Using the CallLogContent Provider:
      • Android provides a content provider to access the call log on the handset via the class android.provider.CallLog.
      • You can use the CallLog to filter recently dialed calls, received, and missed calls.
      • The CallLog is a useful content provider for customer relationship management (CRM) applications.
      • Accessing Content Providers That Require Permissions: android.permission.READ_CONTACTS
    • Using the Browser Content Provider:
      • The Browser content provider exposes the user’s browser site history and their bookmarked websites.
      • You access this con-tent provider via the android.provider.Browser class.
      • You might use the Browser content provider to add a bookmark for your application support website.
    • Using the Contacts Content Provider:
      • People always want phone numbers handy for calling friends, family, co-workers, and clients. 
      • Additionally, most phones show the identity of the caller based on the contacts application, including nicknames, photos, or icons.
      • Android provides a built-in Contact application, and the contact data is exposed to other Android applications using the content provider interface.
      • The content provider for accessing user contacts was originally called Contacts.
      • This class, called ContactsContract, includes a sub-class called ContactsContract.Contacts. 
      • This is preferred contacts content provider, as of API Level 5.
    • Using the UserDictionaryContent Provider:
      • You can use this content provider for predictive text input on text fields and other user input mechanisms.
      • Individual words stored in the dictionary are weighted by frequency and organized by locale.
      • You can use the addWord() method within the UserDictionary.Words class to add words to the custom user dictionary.
    • Using the SettingsContent Provider:
      • You can use this content provider to access the device settings and user preferences. 
      • Settings are organized much as they are in the Settings application—by category.
      • You can find information about the Settings content provider in the android.provider.Settings class.

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form