SlideShare a Scribd company logo
Content
Provider
Android Training
By Khaled Anaqwa
Content Providers
 Content providers manage access to a
structured set of data.
 Encapsulate the data, and provide
mechanisms for defining data security.
 Content providers are the standard
interface that connects data in one
process with code running in another
process.
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 ContentResolver object communicates
with the provider object, an instance of a
class that implements ContentProvider.
 The provider object receives data requests
from clients, performs the requested action,
and returns the results.
Calendar Provider part of
Android platform
 Calendar Provider
 Contacts Provider
Calendar Provider
 The Calendar Provider is a repository for a
user's calendar events.
 The Calendar Provider API allows you to
perform query, insert, update, and delete
operations on calendars, events,
attendees, reminders, and so on
 Every content provider exposes a public URI
(wrapped as a Uri object) 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://".
 This identifies the data as being controlled by a
content provider.
 The Calendar Provider defines constants for the URIs
for each of its classes (tables). These URIs have the
format <class>.CONTENT_URI. For example,
Events.CONTENT_URI.
Android Training (Content Provider)
How To Use
 Uses Permissions
 ContentResolver
 Querying
Uses Permissions
<uses-permission
android:name="android.permission.READ_CAL
ENDAR" />
<uses-permission
android:name="android.permission.WRITE_CA
LENDAR" />
ContentResolver
ContentResolver cr = getContentResolver();
Uri uri = Calendars.CONTENT_URI;
Query Example
 Cursor c = cr.query(uri, projection,
selection, selectionArgs, null);
 update(updateUri, values, null, null);
 insert(Events.CONTENT_URI, values);
Demo
 Create Event add it to calendar
 Adding Reminder
Task
 Select all events
Contacts Provider
 It’s a powerful and flexible Android component
that manages the device's central repository of
data about people.
 It’s the source of data you see in the device's
(contacts application , or your own application)
and transfer data between the device and online
services.
 It’s accommodates a wide range of data sources
and tries to manage as much data as possible for
each person, ( its organization is complex)
 Because of this, it's includes an extensive set of
contract classes and interfaces that facilitate both
data retrieval and modification.
Contacts Provider
Organization
 The Contacts Provider is an Android
content provider component. It maintains
three types of data about a person, each
of which corresponds to a table offered
by the provider
Android Training (Content Provider)
 The three tables are commonly referred to
by the names of their contract classes
 ContactsContract.Contacts table
Rows representing different people, based on
aggregations of raw contact rows.
 ContactsContract.RawContacts table
Rows containing a summary of a person's data,
specific to a user account and type.
 ContactsContract.Data table
Rows containing the details for raw contact,
such as email addresses or phone numbers.
Demo
 Open Contact Manager form Samples
 Task
 Modify List of Contacts add (_ID ,
HAS_PHONE_NUMBER )
Content Provider
 A content provider manages access to a central
repository of data.
 You implement a provider as one or more classes
in an Android application, along with elements in
the manifest file.
 One of your classes implements a subclass
ContentProvider, which is the interface between
your provider and other applications.
 Although content providers are meant to make
data available to other applications, you may of
course have activities in your application that
allow the user to query and modify the data
managed by your provider.
Before You Start Building C.P.
 You want to offer complex data or files to
other applications.
 You want to allow users to copy complex
data from your app into other apps.
 You want to provide custom search
suggestions using the search framework.
 You don't need a provider to use an
SQLite database if the use is entirely within
your own application.

More Related Content

PPTX
Android content provider explained
PDF
Android contentprovider
PPT
android content providers
PPTX
Custom content provider in android
PPTX
05 content providers - Android
PPTX
Android Insights - 3 [Content Providers]
PPTX
Content provider in_android
PPTX
Android content providers
Android content provider explained
Android contentprovider
android content providers
Custom content provider in android
05 content providers - Android
Android Insights - 3 [Content Providers]
Content provider in_android
Android content providers

What's hot (20)

ODP
Android App Development - 10 Content providers
PPT
Content providers in Android
PPTX
Android Training Session 1
PPTX
Day 15: Content Provider: Using Contacts API
PPTX
Android Trainning Session 2
ODT
ACADGILD:: ANDROID LESSON
PPT
PPTX
Create an android app for database creation using.pptx
PDF
Secure Sharing PHI PCI PII -Android app_Content Provider
PPTX
Recovered file 1
PDF
Android - Saving data
PDF
Backendless apps
PDF
Asp net interview_questions
PDF
Data Binding and Data Grid View Classes
PPTX
Programming web application
PPT
Ado.net
PPT
Lecture14Slides.ppt
PPTX
Lesson 06 Styles and Templates in WPF
PPT
Simple Data Binding
PPTX
Lesson 05 Data Binding in WPF
Android App Development - 10 Content providers
Content providers in Android
Android Training Session 1
Day 15: Content Provider: Using Contacts API
Android Trainning Session 2
ACADGILD:: ANDROID LESSON
Create an android app for database creation using.pptx
Secure Sharing PHI PCI PII -Android app_Content Provider
Recovered file 1
Android - Saving data
Backendless apps
Asp net interview_questions
Data Binding and Data Grid View Classes
Programming web application
Ado.net
Lecture14Slides.ppt
Lesson 06 Styles and Templates in WPF
Simple Data Binding
Lesson 05 Data Binding in WPF
Ad

Viewers also liked (20)

PPTX
Android Training (Storing & Shared Preferences)
PPTX
Android - Broadcast Receiver
KEY
Improving Android Text Layout in Localisation
PPT
Data Storage In Android
PDF
Structural Relationship between Content Resolver and Content Provider of Andr...
PDF
Android UI Testing with uiautomator
PDF
Android complete basic Guide
PPTX
Android Firebase
PDF
Android Data Persistence
PPTX
Android Training (android fundamental)
PPTX
Android Training (Broadcast Receiver)
PPTX
Android Training (Services)
PPTX
Android Training (Touch)
PPTX
Android training (android style)
PPTX
Android Training (Notifications)
PPTX
Android Training (ScrollView , Horizontal ScrollView WebView)
PPT
Chapter 5 ms access-1
PPT
Day 6: Android BroadcastReceiver Component
PDF
Testing on Android
PDF
Android App development and test environment, Understaing android app structure
Android Training (Storing & Shared Preferences)
Android - Broadcast Receiver
Improving Android Text Layout in Localisation
Data Storage In Android
Structural Relationship between Content Resolver and Content Provider of Andr...
Android UI Testing with uiautomator
Android complete basic Guide
Android Firebase
Android Data Persistence
Android Training (android fundamental)
Android Training (Broadcast Receiver)
Android Training (Services)
Android Training (Touch)
Android training (android style)
Android Training (Notifications)
Android Training (ScrollView , Horizontal ScrollView WebView)
Chapter 5 ms access-1
Day 6: Android BroadcastReceiver Component
Testing on Android
Android App development and test environment, Understaing android app structure
Ad

Similar to Android Training (Content Provider) (20)

PDF
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
PDF
Mobile Application Development -Lecture 11 & 12.pdf
PDF
Mobile Application Development -Lecture 09 & 10.pdf
PDF
Mobile Application Development Lecture 05 & 06.pdf
PPT
Service-Finder presentation at ESTC2008
PPT
Realizing Service Finder at ESTC 2008
PDF
Documentum introduction
PPT
5 steps to becoming a JISC IE content provider
DOCX
PPTX
Lec-3-Mobile Application Development.pptx
PPTX
JAX-RS. Developing RESTful APIs with Java
PDF
Web Service Discovery Mechanisms Based on IR Models
PPTX
Mobile application Development-UNIT-V (1).pptx
PDF
Slides from Perth MuleSoft Meetup March 2025
PPTX
Building nTier Applications with Entity Framework Services
PPTX
Interoperability in Digital Libraries
PPTX
Android Application Components-BroadcastReceiver_Content Provider.pptx
PPT
Cloud as Gift
DOCX
Android resources in android-chapter9
ODP
Nativa Android Applications development
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development Lecture 05 & 06.pdf
Service-Finder presentation at ESTC2008
Realizing Service Finder at ESTC 2008
Documentum introduction
5 steps to becoming a JISC IE content provider
Lec-3-Mobile Application Development.pptx
JAX-RS. Developing RESTful APIs with Java
Web Service Discovery Mechanisms Based on IR Models
Mobile application Development-UNIT-V (1).pptx
Slides from Perth MuleSoft Meetup March 2025
Building nTier Applications with Entity Framework Services
Interoperability in Digital Libraries
Android Application Components-BroadcastReceiver_Content Provider.pptx
Cloud as Gift
Android resources in android-chapter9
Nativa Android Applications development

More from Khaled Anaqwa (8)

PPTX
Android Training (Storing data using SQLite)
PPTX
Android Training (Animation)
PPTX
Android Training (Sensors)
PPTX
Android Training (Media)
PPTX
Android Training (AdapterView & Adapter)
PPTX
Android Training (Android UI)
PPTX
Android Training (Intro)
PPTX
Android Training (Java Review)
Android Training (Storing data using SQLite)
Android Training (Animation)
Android Training (Sensors)
Android Training (Media)
Android Training (AdapterView & Adapter)
Android Training (Android UI)
Android Training (Intro)
Android Training (Java Review)

Recently uploaded (20)

PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mushroom cultivation and it's methods.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
August Patch Tuesday
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Chapter 5: Probability Theory and Statistics
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Encapsulation_ Review paper, used for researhc scholars
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Mushroom cultivation and it's methods.pdf
A novel scalable deep ensemble learning framework for big data classification...
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
cloud_computing_Infrastucture_as_cloud_p
August Patch Tuesday
Unlocking AI with Model Context Protocol (MCP)
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
A comparative analysis of optical character recognition models for extracting...
Assigned Numbers - 2025 - Bluetooth® Document
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25-Week II
SOPHOS-XG Firewall Administrator PPT.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Chapter 5: Probability Theory and Statistics
A comparative study of natural language inference in Swahili using monolingua...
DP Operators-handbook-extract for the Mautical Institute
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Encapsulation_ Review paper, used for researhc scholars

Android Training (Content Provider)

  • 2. Content Providers  Content providers manage access to a structured set of data.  Encapsulate the data, and provide mechanisms for defining data security.  Content providers are the standard interface that connects data in one process with code running in another process.
  • 3. 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 ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider.  The provider object receives data requests from clients, performs the requested action, and returns the results.
  • 4. Calendar Provider part of Android platform  Calendar Provider  Contacts Provider
  • 5. Calendar Provider  The Calendar Provider is a repository for a user's calendar events.  The Calendar Provider API allows you to perform query, insert, update, and delete operations on calendars, events, attendees, reminders, and so on
  • 6.  Every content provider exposes a public URI (wrapped as a Uri object) 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://".  This identifies the data as being controlled by a content provider.  The Calendar Provider defines constants for the URIs for each of its classes (tables). These URIs have the format <class>.CONTENT_URI. For example, Events.CONTENT_URI.
  • 8. How To Use  Uses Permissions  ContentResolver  Querying
  • 10. ContentResolver ContentResolver cr = getContentResolver(); Uri uri = Calendars.CONTENT_URI;
  • 11. Query Example  Cursor c = cr.query(uri, projection, selection, selectionArgs, null);  update(updateUri, values, null, null);  insert(Events.CONTENT_URI, values);
  • 12. Demo  Create Event add it to calendar  Adding Reminder
  • 14. Contacts Provider  It’s a powerful and flexible Android component that manages the device's central repository of data about people.  It’s the source of data you see in the device's (contacts application , or your own application) and transfer data between the device and online services.  It’s accommodates a wide range of data sources and tries to manage as much data as possible for each person, ( its organization is complex)  Because of this, it's includes an extensive set of contract classes and interfaces that facilitate both data retrieval and modification.
  • 15. Contacts Provider Organization  The Contacts Provider is an Android content provider component. It maintains three types of data about a person, each of which corresponds to a table offered by the provider
  • 17.  The three tables are commonly referred to by the names of their contract classes  ContactsContract.Contacts table Rows representing different people, based on aggregations of raw contact rows.  ContactsContract.RawContacts table Rows containing a summary of a person's data, specific to a user account and type.  ContactsContract.Data table Rows containing the details for raw contact, such as email addresses or phone numbers.
  • 18. Demo  Open Contact Manager form Samples  Task  Modify List of Contacts add (_ID , HAS_PHONE_NUMBER )
  • 19. Content Provider  A content provider manages access to a central repository of data.  You implement a provider as one or more classes in an Android application, along with elements in the manifest file.  One of your classes implements a subclass ContentProvider, which is the interface between your provider and other applications.  Although content providers are meant to make data available to other applications, you may of course have activities in your application that allow the user to query and modify the data managed by your provider.
  • 20. Before You Start Building C.P.  You want to offer complex data or files to other applications.  You want to allow users to copy complex data from your app into other apps.  You want to provide custom search suggestions using the search framework.
  • 21.  You don't need a provider to use an SQLite database if the use is entirely within your own application.

Editor's Notes

  • #13: long calID = 3; long startMillis = 0; long endMillis = 0; Calendar beginTime = Calendar.getInstance(); beginTime.set(2012, 9, 14, 7, 30); startMillis = beginTime.getTimeInMillis(); Calendar endTime = Calendar.getInstance(); endTime.set(2012, 9, 14, 8, 45); endMillis = endTime.getTimeInMillis(); ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); values.put(Events.DTSTART, startMillis); values.put(Events.DTEND, endMillis); values.put(Events.TITLE, "Jazzercise"); values.put(Events.DESCRIPTION, "Group workout"); values.put(Events.CALENDAR_ID, calID); values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles"); Uri uri = cr.insert(Events.CONTENT_URI, values); // get the event ID that is the last element in the Uri long eventID = Long.parseLong(uri.getLastPathSegment()); //add reminder ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); values.put(Reminders.MINUTES, 15); values.put(Reminders.EVENT_ID, eventID); values.put(Reminders.METHOD, Reminders.METHOD_ALERT); Uri uri = cr.insert(Reminders.CONTENT_URI, values);
  • #14: public static final String[] INSTANCE_PROJECTION = new String[] { Instances.EVENT_ID, // 0 Instances.BEGIN, // 1 Instances.TITLE // 2 }; // The indices for the projection array above. private static final int PROJECTION_ID_INDEX = 0; private static final int PROJECTION_BEGIN_INDEX = 1; private static final int PROJECTION_TITLE_INDEX = 2; alendar beginTime = Calendar.getInstance(); beginTime.set(2011, 9, 23, 8, 0); long startMillis = beginTime.getTimeInMillis(); Calendar endTime = Calendar.getInstance(); endTime.set(2011, 10, 24, 8, 0); long endMillis = endTime.getTimeInMillis(); Cursor cur = null; ContentResolver cr = getContentResolver(); // The ID of the recurring event whose instances you are searching // for in the Instances table String selection = Instances.EVENT_ID + " = ?"; String[] selectionArgs = new String[] {"207"}; // Construct the query with the desired date range. Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, startMillis); ContentUris.appendId(builder, endMillis); // Submit the query cur = cr.query(builder.build(), INSTANCE_PROJECTION, selection, selectionArgs, null); while (cur.moveToNext()) { String title = null; long eventID = 0; long beginVal = 0; // Get the field values eventID = cur.getLong(PROJECTION_ID_INDEX); beginVal = cur.getLong(PROJECTION_BEGIN_INDEX); title = cur.getString(PROJECTION_TITLE_INDEX); // Do something with the values. Log.i(DEBUG_TAG, "Event: " + title); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(beginVal); DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); Log.i(DEBUG_TAG, "Date: " + formatter.format(calendar.getTime())); } }