SlideShare a Scribd company logo
Android Content Provider
What is a Content Provider?
• Store and retrieve data and make it accessible
to all applications
• Only way to share data across applications
o There's no common storage area that all Android
packages can access
• Two types of content providers
o Android's built-in content providers
o Custom content providers we create
Why?
• Sometimes it is required to share data across
applications. This is where content providers
become very useful.
Content Provider
Android's Built-in Content Providers
• Android ships with a number of content
providers for common data types
o audio, video, images, personal contact
information, and so on
o android.provider package
• We can query these providers for the data
they contain
Android's Built-in Content Providers
• Browser
o Browser bookmarks, browser history
• CallLog
o Missed calls, call details
• Contacts
o Contact details
• MediaStore
o Media files
• Settings
o Device settings and preferences
How do you make your data public?
• Two options
o You can create your own content provider
(extending ContentProvider class) or
o You can add the data to an existing provider — if
there's one that controls the same type of data
and you have permission to write to it.
Content Provider Implementation &
Usage Model
• All content providers implement a common
interface for
o querying the provider and returning results
o adding
o altering
o deleting
• How a content provider actually stores its data
under the cover is up to its designer.
• Clients access content providers indirectly through
ContentResolver
Data Model
• Content providers expose their data as a
simple table (like in a database) model
o Each row is a record and each column is data of a
particular type and meaning
o Every record includes a numeric _ID field that
uniquely identifies the record within the table
Content Provider
• Each content provider exposes a public URI
(wrapped as a Uri object) that uniquely
identifies its data set.
o 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://".
o The “content:” scheme identifies the data as
being controlled by a content provider.
Built-in URI Definitions
• Android defines CONTENT_URI constants for
all the providers that come with the platform.
• For example, the URI for the table that
matches phone numbers to people and the
URI for the table that holds pictures of people
(both controlled by the Contacts content
provider) are:
android.provider.Contacts.Phones.CONTENT_URI
android.provider.Contacts.Photos.CONTENT_URI
URI
• The URI constant is used in all interactions
with the content provider
o Every ContentResolver method takes the URI as
its first argument.
• It's what identifies which provider the
ContentResolver should talk to and which
table of the provider is being targeted.
URI Structure
A: Standard prefix indicating that the data is
controlled by a content provider. It's never
modified.
B: The authority part of the URI; it identifies the
content provider.
C: The path that the content provider uses to
determine what kind of data (which table) is being
requested.
D: The ID of the specific record being requested
What a Query Returns
• A query returns a set of zero or more records
• The retrieved data is exposed by a Cursor
object that can be used to iterate backward or
forward through the result set.
o You can use Cursor object only to read the data.
o To add, modify, or delete data, you must use a
ContentResolver object.
Custom Content Provider
Custom Content Provider
Custom Content Provider
Developing a Custom Content Provider
1. Extend the
ContentProvider
class.
2. In the onCreate()
method, create a
new instance of the
database helper
class.
Custom Content Provider...
Custom Content Provider...
Suppose, we need to provide access to 2
tables through this single content provider. As
we have only one method per CRUD
operation, we need a way to differentiate
between accesses to these two tables.
3. We need to define content URI paths to each
table. These are defined in a public final class
which can be used by both provider and user
as a contract: (see next slide)
Custom Content Provider...
Custom Content Provider...
Now comes the issue of differentiating
between paths. The idea is to match a URI and
then taking appropriate actions for the
corresponding table path.
4. Add a UriMatcher to the provider and add
expected URI patterns to it.
5. In the query() method, get the appropriate
table name from the URI.
Custom Content Provider...
Custom Content Provider...
6. Now write the actual query method:
• You should add this URI to notification
observables by calling setNotificationUri() so that
if this cursor is directly used in a ListView,
updating or inserting or deleting data in the table
represented by this URI would notify the ListView
of this data change
Custom Content Provider...
7. insert, update and delete methods are
similar.
• insert() returns the Uri with the newly inserted ID
appended.
• update() and delete() returns the number of
rows affected.
• You should call
notifyChangeToContentObservers(uri); before
returning from these methods.
Custom Content Provider...
We need to provide MIME type of the data returned by a URI.
8. The overridden method getType(Uri uri) needs to be
filled-in.
– For content URIs that point to a row or rows of table data, getType()
should return a MIME type in Androids vendor-specific MIME format:
• Type part: vnd
• Subtype part:
– If the URI pattern is for a single row: android.cursor.item/
– If the URI pattern is for more than one row: android.cursor.dir/
• Provider-specific part: vnd.<name>.<type>
– You supply the <name> and <type>.
– The <name> value should be globally unique, and the <type> value should be
unique to the corresponding URI pattern.
– A good choice for <name> is your companys name or some part of your
applications Android package name.
– A good choice for the <type> is a string that identifies the table associated with
the URI.
Custom Content Provider...
Custom Content Provider...
Custom Content Provider...
9. We need to declare the provider in the
manifest.xml file:
Custom Content Provider...
10. Finally, we need to define permissions for
applications who wish to access the
provider.
Different forms of permissions:
• Single read-write provider-level permission
– One permission that controls both read and write access to the
entire provider, specified with the android:permission attribute of the
<provider> element in manifest.xml.
• Separate read and write provider-level permission
– A read permission and a write permission for the entire provider.
– Specified with the android:readPermission and
android:writePermission attributes of the <provider> element.
– They take precedence over the permission required by
android:permission.
Custom Content Provider...
• Path-level permission
– Read, write, or read/write permission for a content
URI in your provider.
– You specify each URI you want to control with a
<path-permission> child element of the <provider>
element.
DEMO TIME
THANK YOU ☺

More Related Content

What's hot

OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
Christopher Frohoff
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
suraj pandey
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
Peter R. Egli
 
Jenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelinesJenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelines
Luca Milanesio
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
Raja Sekhar
 
Cs8493 unit 5
Cs8493 unit 5Cs8493 unit 5
Cs8493 unit 5
Kathirvel Ayyaswamy
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
Siddique Ibrahim
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systemssumitjain2013
 
Thread
ThreadThread
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Arafat Hossan
 
Java rmi
Java rmiJava rmi
Java rmi
kamal kotecha
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
Anwar Hasan Shuvo
 
Chapter 8 distributed file systems
Chapter 8 distributed file systemsChapter 8 distributed file systems
Chapter 8 distributed file systemsAbDul ThaYyal
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
Muthukumaran Subramanian
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
Muhammad Baqar Kazmi
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
Akhila Prabhakaran
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating System
Kathirvel Ayyaswamy
 

What's hot (20)

OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Jenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelinesJenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelines
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Cs8493 unit 5
Cs8493 unit 5Cs8493 unit 5
Cs8493 unit 5
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
 
Fault tolerance in distributed systems
Fault tolerance in distributed systemsFault tolerance in distributed systems
Fault tolerance in distributed systems
 
Lecture 1 oop
Lecture 1 oopLecture 1 oop
Lecture 1 oop
 
Thread
ThreadThread
Thread
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java rmi
Java rmiJava rmi
Java rmi
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
 
Chapter 8 distributed file systems
Chapter 8 distributed file systemsChapter 8 distributed file systems
Chapter 8 distributed file systems
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating System
 

Similar to Custom content provider in android

Android Insights - 3 [Content Providers]
Android Insights - 3 [Content Providers]Android Insights - 3 [Content Providers]
Android Insights - 3 [Content Providers]
Sharafat Ibn Mollah Mosharraf
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIAhsanul Karim
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_android
PRITI TELMORE
 
Android contentprovider
Android contentproviderAndroid contentprovider
Android contentproviderKrazy Koder
 
Android content providers
Android content providersAndroid content providers
Android content providers
Kurt Mbanje
 
android content providers
android content providersandroid content providers
android content providersDeepa Rani
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
Khaled Anaqwa
 
CrossRef Text & Data Mining - UKSG 2015
CrossRef Text & Data Mining - UKSG 2015CrossRef Text & Data Mining - UKSG 2015
CrossRef Text & Data Mining - UKSG 2015
Crossref
 
Bn1 1020 demo android
Bn1 1020 demo  androidBn1 1020 demo  android
Bn1 1020 demo android
conline training
 
Android Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxAndroid Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptx
KNANTHINIMCA
 
UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...
UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...
UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...
UKSG: connecting the knowledge community
 
Jisc Publications Router poster
Jisc Publications Router posterJisc Publications Router poster
Jisc Publications Router poster
EDINA, University of Edinburgh
 
Development of Web Services for Android Applications
Development of Web Services for Android ApplicationsDevelopment of Web Services for Android Applications
Development of Web Services for Android Applications
Md Ashraful Haque
 
Content package - Mobile computing
Content package - Mobile computingContent package - Mobile computing
Content package - Mobile computing
Priyanka Rana
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
Hussain Behestee
 
Android101 - Content Providers
Android101 - Content ProvidersAndroid101 - Content Providers
Android101 - Content Providers
jromero1214
 
NISO Open Discovery Initiative, ALA Midwinter
NISO Open Discovery Initiative, ALA MidwinterNISO Open Discovery Initiative, ALA Midwinter
NISO Open Discovery Initiative, ALA Midwinter
National Information Standards Organization (NISO)
 
Patham "NISO-ODI (Open Discovery Initiative) Standards Update"
Patham "NISO-ODI (Open Discovery Initiative) Standards Update"Patham "NISO-ODI (Open Discovery Initiative) Standards Update"
Patham "NISO-ODI (Open Discovery Initiative) Standards Update"
National Information Standards Organization (NISO)
 

Similar to Custom content provider in android (20)

Android Insights - 3 [Content Providers]
Android Insights - 3 [Content Providers]Android Insights - 3 [Content Providers]
Android Insights - 3 [Content Providers]
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts API
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_android
 
Android contentprovider
Android contentproviderAndroid contentprovider
Android contentprovider
 
Android content providers
Android content providersAndroid content providers
Android content providers
 
android content providers
android content providersandroid content providers
android content providers
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
 
CrossRef Text & Data Mining - UKSG 2015
CrossRef Text & Data Mining - UKSG 2015CrossRef Text & Data Mining - UKSG 2015
CrossRef Text & Data Mining - UKSG 2015
 
Bn1 1020 demo android
Bn1 1020 demo  androidBn1 1020 demo  android
Bn1 1020 demo android
 
Android Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptxAndroid Application Components-BroadcastReceiver_Content Provider.pptx
Android Application Components-BroadcastReceiver_Content Provider.pptx
 
UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...
UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...
UKSG Conference 2015 - CrossRef Text and Data Mining Services: one year in Ra...
 
Jisc Publications Router poster
Jisc Publications Router posterJisc Publications Router poster
Jisc Publications Router poster
 
Development of Web Services for Android Applications
Development of Web Services for Android ApplicationsDevelopment of Web Services for Android Applications
Development of Web Services for Android Applications
 
Content package - Mobile computing
Content package - Mobile computingContent package - Mobile computing
Content package - Mobile computing
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
 
Android101 - Content Providers
Android101 - Content ProvidersAndroid101 - Content Providers
Android101 - Content Providers
 
NISO Open Discovery Initiative, ALA Midwinter
NISO Open Discovery Initiative, ALA MidwinterNISO Open Discovery Initiative, ALA Midwinter
NISO Open Discovery Initiative, ALA Midwinter
 
Patham "NISO-ODI (Open Discovery Initiative) Standards Update"
Patham "NISO-ODI (Open Discovery Initiative) Standards Update"Patham "NISO-ODI (Open Discovery Initiative) Standards Update"
Patham "NISO-ODI (Open Discovery Initiative) Standards Update"
 

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 

Custom content provider in android

  • 2. What is a Content Provider? • Store and retrieve data and make it accessible to all applications • Only way to share data across applications o There's no common storage area that all Android packages can access • Two types of content providers o Android's built-in content providers o Custom content providers we create
  • 3. Why? • Sometimes it is required to share data across applications. This is where content providers become very useful.
  • 5. Android's Built-in Content Providers • Android ships with a number of content providers for common data types o audio, video, images, personal contact information, and so on o android.provider package • We can query these providers for the data they contain
  • 6. Android's Built-in Content Providers • Browser o Browser bookmarks, browser history • CallLog o Missed calls, call details • Contacts o Contact details • MediaStore o Media files • Settings o Device settings and preferences
  • 7. How do you make your data public? • Two options o You can create your own content provider (extending ContentProvider class) or o You can add the data to an existing provider — if there's one that controls the same type of data and you have permission to write to it.
  • 8. Content Provider Implementation & Usage Model • All content providers implement a common interface for o querying the provider and returning results o adding o altering o deleting • How a content provider actually stores its data under the cover is up to its designer. • Clients access content providers indirectly through ContentResolver
  • 9. Data Model • Content providers expose their data as a simple table (like in a database) model o Each row is a record and each column is data of a particular type and meaning o Every record includes a numeric _ID field that uniquely identifies the record within the table
  • 10. Content Provider • Each content provider exposes a public URI (wrapped as a Uri object) that uniquely identifies its data set. o 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://". o The “content:” scheme identifies the data as being controlled by a content provider.
  • 11. Built-in URI Definitions • Android defines CONTENT_URI constants for all the providers that come with the platform. • For example, the URI for the table that matches phone numbers to people and the URI for the table that holds pictures of people (both controlled by the Contacts content provider) are: android.provider.Contacts.Phones.CONTENT_URI android.provider.Contacts.Photos.CONTENT_URI
  • 12. URI • The URI constant is used in all interactions with the content provider o Every ContentResolver method takes the URI as its first argument. • It's what identifies which provider the ContentResolver should talk to and which table of the provider is being targeted.
  • 13. URI Structure A: Standard prefix indicating that the data is controlled by a content provider. It's never modified. B: The authority part of the URI; it identifies the content provider. C: The path that the content provider uses to determine what kind of data (which table) is being requested. D: The ID of the specific record being requested
  • 14. What a Query Returns • A query returns a set of zero or more records • The retrieved data is exposed by a Cursor object that can be used to iterate backward or forward through the result set. o You can use Cursor object only to read the data. o To add, modify, or delete data, you must use a ContentResolver object.
  • 18. Developing a Custom Content Provider 1. Extend the ContentProvider class. 2. In the onCreate() method, create a new instance of the database helper class.
  • 20. Custom Content Provider... Suppose, we need to provide access to 2 tables through this single content provider. As we have only one method per CRUD operation, we need a way to differentiate between accesses to these two tables. 3. We need to define content URI paths to each table. These are defined in a public final class which can be used by both provider and user as a contract: (see next slide)
  • 22. Custom Content Provider... Now comes the issue of differentiating between paths. The idea is to match a URI and then taking appropriate actions for the corresponding table path. 4. Add a UriMatcher to the provider and add expected URI patterns to it. 5. In the query() method, get the appropriate table name from the URI.
  • 24. Custom Content Provider... 6. Now write the actual query method: • You should add this URI to notification observables by calling setNotificationUri() so that if this cursor is directly used in a ListView, updating or inserting or deleting data in the table represented by this URI would notify the ListView of this data change
  • 25. Custom Content Provider... 7. insert, update and delete methods are similar. • insert() returns the Uri with the newly inserted ID appended. • update() and delete() returns the number of rows affected. • You should call notifyChangeToContentObservers(uri); before returning from these methods.
  • 26. Custom Content Provider... We need to provide MIME type of the data returned by a URI. 8. The overridden method getType(Uri uri) needs to be filled-in. – For content URIs that point to a row or rows of table data, getType() should return a MIME type in Androids vendor-specific MIME format: • Type part: vnd • Subtype part: – If the URI pattern is for a single row: android.cursor.item/ – If the URI pattern is for more than one row: android.cursor.dir/ • Provider-specific part: vnd.<name>.<type> – You supply the <name> and <type>. – The <name> value should be globally unique, and the <type> value should be unique to the corresponding URI pattern. – A good choice for <name> is your companys name or some part of your applications Android package name. – A good choice for the <type> is a string that identifies the table associated with the URI.
  • 29. Custom Content Provider... 9. We need to declare the provider in the manifest.xml file:
  • 30. Custom Content Provider... 10. Finally, we need to define permissions for applications who wish to access the provider. Different forms of permissions: • Single read-write provider-level permission – One permission that controls both read and write access to the entire provider, specified with the android:permission attribute of the <provider> element in manifest.xml. • Separate read and write provider-level permission – A read permission and a write permission for the entire provider. – Specified with the android:readPermission and android:writePermission attributes of the <provider> element. – They take precedence over the permission required by android:permission.
  • 31. Custom Content Provider... • Path-level permission – Read, write, or read/write permission for a content URI in your provider. – You specify each URI you want to control with a <path-permission> child element of the <provider> element.