SlideShare a Scribd company logo
Android Content Providers
Kurt Mbanje : DStv Digital Media
+KurtMbanje
@ckurtm
What's a Content Provider?
• They provide content to applications.
• They encapsulate data and provide it to applications through the single
ContentResolver interface
Why?
• Share data between applications.
• Predictive search within your app
• Leverage power of loaders with cursors.
Ok so how does this work?
App 1 has content (database) and a registered ContentProvider
App 2 uses ContentResolver and content Uri to request data from a
ContentProvider
Android uses the Uri provided by App 2 to find the matching registered
ContentProvider to send and receive data from
The ContentProvider for App 1 uses this Uri to find the data and returns it to the
ContentResolver supplied by App 2
Components
• android.content.ContentResolver getContext().getContentResolver()
• android.net.Uri
Content Uri android.net.Uri
• The scheme – content://
• Authority
• Path usually matches a table name in your database
• ID (optional) used for further filtering e.g. to get a specific row
android.content.ContentResolver
public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Query
insert(Uri url, ContentValues values)
INSERT
update(Uri uri, ContentValues values, String where, String[] selectionArgs)
Update
delete(Uri url, String where, String[] selectionArgs)
Delete
android.content.ContentResolver
Query
Example: Query Calendar
android.content.ContentResolver
public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Query
insert(Uri url, ContentValues values)
INSERT
update(Uri uri, ContentValues values, String where, String[] selectionArgs)
Update
delete(Uri url, String where, String[] selectionArgs)
Delete
android.content.ContentResolver
public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Query
insert(Uri url, ContentValues values)
INSERT
update(Uri uri, ContentValues values, String where, String[] selectionArgs)
Update
delete(Uri url, String where, String[] selectionArgs)
Delete
Example: Update event in Calendar
android.content.ContentResolver
public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
Query
insert(Uri url, ContentValues values)
INSERT
update(Uri uri, ContentValues values, String where, String[] selectionArgs)
Update
delete(Uri url, String where, String[] selectionArgs)
Delete
Create a Content Provider
1. Create an Authority
2. Create a your class that extends from ContentProvider
3. Implement the matching ContentResolver methods
4. Register your ContentProvider in manifest & mark export to true (only if
you wish to share your data)
1: Create an Authority
2: Create your ContentProvider
1. Extend From ContentProvider
2. Implement OnCreate
3. Create your Uri matcher
4. Overide methods e.g. query
3: Create your ContentProvider : Query Method
Type - public String getType(Uri uri)
Delete - public abstract int delete (Uri uri, String selection, String[] selectionArgs)
Update - public abstract int update (Uri uri, ContentValues values, String selection, String[] selectionArgs)
Insert - public abstract Uri insert (Uri uri, ContentValues values)
3: Create your ContentProvider : Other Methods
4: Register your ContentProvider
Android content providers
DroidProvider
https://github.com/ckurtm/DroidProvider
Thanks
+KurtMbanje

More Related Content

PPTX
Content provider in_android
PDF
Android contentprovider
PPTX
FAKE NEWS DETECTION (1).pptx
PPTX
Detecting fake news .pptx
PPTX
Fake News detection.pptx
PDF
Manual autoplay media studio 6.0
PPTX
Chapter 06 constructors and destructors
PDF
Deep Learning for real-time emotion recognition from face images
Content provider in_android
Android contentprovider
FAKE NEWS DETECTION (1).pptx
Detecting fake news .pptx
Fake News detection.pptx
Manual autoplay media studio 6.0
Chapter 06 constructors and destructors
Deep Learning for real-time emotion recognition from face images

What's hot (20)

PPTX
Big Data - Applications and Technologies Overview
PDF
IoT Network Attack Detection using Supervised Machine Learning
PPT
android content providers
PPTX
Artificial Face Aging
PPTX
Fake news detection project
PPTX
Object Oriented Analysis (Coad-Yourdon)
PPT
Java beans
PDF
Computer Vision
PPTX
Cookie & Session In ASP.NET
PPT
Packages and interfaces
PPTX
Malware Detection Using Machine Learning Techniques
PPT
3.2 partitioning methods
PPTX
Information Retrieval-4(inverted index_&_query handling)
PPTX
Object oriented programming in python
PPTX
Object oriented programming with python
PPTX
Android Intent.pptx
ODP
Topic Modeling
PPS
Inheritance
PPTX
Object detection.pptx
PDF
Smart Fire Detection System using Image Processing
Big Data - Applications and Technologies Overview
IoT Network Attack Detection using Supervised Machine Learning
android content providers
Artificial Face Aging
Fake news detection project
Object Oriented Analysis (Coad-Yourdon)
Java beans
Computer Vision
Cookie & Session In ASP.NET
Packages and interfaces
Malware Detection Using Machine Learning Techniques
3.2 partitioning methods
Information Retrieval-4(inverted index_&_query handling)
Object oriented programming in python
Object oriented programming with python
Android Intent.pptx
Topic Modeling
Inheritance
Object detection.pptx
Smart Fire Detection System using Image Processing
Ad

Similar to Android content providers (20)

PPTX
Custom content provider in android
PPTX
Android101 - Content Providers
ODP
Android App Development - 10 Content providers
PPTX
Android Training (Content Provider)
PPTX
Day 15: Content Provider: Using Contacts API
PPTX
Android Database
PPTX
Android Application Components-BroadcastReceiver_Content Provider.pptx
PPTX
Data Transfer between Activities & Databases
KEY
Android開発の基礎_20101218
PDF
Cursor & Content Value.pdf
PPTX
05 content providers - Android
PDF
Sensor thingsapi webinar-#3-rest-for-iot-api-20151210
PPTX
Data Transfer between Activities & Databases
PPTX
SQLite Opening .pptx
PPT
Wis2011_presentation_Realtime_Events_on_LOD
PPTX
Development of Twitter Application #6 - Trends
PDF
Murach: How to transfer data from controllers
PPTX
Lesson 05 Data Binding in WPF
PPTX
Apache Lucene Basics
PPTX
Mobile application Development-UNIT-V (1).pptx
Custom content provider in android
Android101 - Content Providers
Android App Development - 10 Content providers
Android Training (Content Provider)
Day 15: Content Provider: Using Contacts API
Android Database
Android Application Components-BroadcastReceiver_Content Provider.pptx
Data Transfer between Activities & Databases
Android開発の基礎_20101218
Cursor & Content Value.pdf
05 content providers - Android
Sensor thingsapi webinar-#3-rest-for-iot-api-20151210
Data Transfer between Activities & Databases
SQLite Opening .pptx
Wis2011_presentation_Realtime_Events_on_LOD
Development of Twitter Application #6 - Trends
Murach: How to transfer data from controllers
Lesson 05 Data Binding in WPF
Apache Lucene Basics
Mobile application Development-UNIT-V (1).pptx
Ad

Android content providers

  • 1. Android Content Providers Kurt Mbanje : DStv Digital Media +KurtMbanje @ckurtm
  • 2. What's a Content Provider? • They provide content to applications. • They encapsulate data and provide it to applications through the single ContentResolver interface
  • 3. Why? • Share data between applications. • Predictive search within your app • Leverage power of loaders with cursors.
  • 4. Ok so how does this work? App 1 has content (database) and a registered ContentProvider App 2 uses ContentResolver and content Uri to request data from a ContentProvider Android uses the Uri provided by App 2 to find the matching registered ContentProvider to send and receive data from The ContentProvider for App 1 uses this Uri to find the data and returns it to the ContentResolver supplied by App 2
  • 6. Content Uri android.net.Uri • The scheme – content:// • Authority • Path usually matches a table name in your database • ID (optional) used for further filtering e.g. to get a specific row
  • 7. android.content.ContentResolver public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) Query insert(Uri url, ContentValues values) INSERT update(Uri uri, ContentValues values, String where, String[] selectionArgs) Update delete(Uri url, String where, String[] selectionArgs) Delete
  • 10. android.content.ContentResolver public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) Query insert(Uri url, ContentValues values) INSERT update(Uri uri, ContentValues values, String where, String[] selectionArgs) Update delete(Uri url, String where, String[] selectionArgs) Delete
  • 11. android.content.ContentResolver public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) Query insert(Uri url, ContentValues values) INSERT update(Uri uri, ContentValues values, String where, String[] selectionArgs) Update delete(Uri url, String where, String[] selectionArgs) Delete
  • 12. Example: Update event in Calendar
  • 13. android.content.ContentResolver public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) Query insert(Uri url, ContentValues values) INSERT update(Uri uri, ContentValues values, String where, String[] selectionArgs) Update delete(Uri url, String where, String[] selectionArgs) Delete
  • 14. Create a Content Provider 1. Create an Authority 2. Create a your class that extends from ContentProvider 3. Implement the matching ContentResolver methods 4. Register your ContentProvider in manifest & mark export to true (only if you wish to share your data)
  • 15. 1: Create an Authority
  • 16. 2: Create your ContentProvider 1. Extend From ContentProvider 2. Implement OnCreate 3. Create your Uri matcher 4. Overide methods e.g. query
  • 17. 3: Create your ContentProvider : Query Method
  • 18. Type - public String getType(Uri uri) Delete - public abstract int delete (Uri uri, String selection, String[] selectionArgs) Update - public abstract int update (Uri uri, ContentValues values, String selection, String[] selectionArgs) Insert - public abstract Uri insert (Uri uri, ContentValues values) 3: Create your ContentProvider : Other Methods
  • 19. 4: Register your ContentProvider