SlideShare une entreprise Scribd logo
1  sur  15
Content Providers
Content providers store and retrieve data and make
it accessible to all applications. They're the only way
to share data across applications; there's no
common storage area that all Android packages can
access.
Android ships with a number of content providers for
common data types (audio, video, images, personal
contact information, and so on). You can see some
of them listed in the android.provider package.
making your own data
public
If you want to make your own data public, you have
two options: You can create your own content
provider (a ContentProvider subclass) or you can
add the data to an existing provider
It's an interface that clients use indirectly, most
generally through ContentResolver objects. You
get a ContentResolver by calling
getContentResolver() from within the
implementation of an Activity or other application
component:
URIs
Each 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://". The content:
scheme identifies the data as being controlled by
a content provider.
Querying a Content Provider
Modifying Data
Data kept by a content provider can be modified by:
 Adding new records
 Adding new values to existing records
 Batch updating existing records
 Deleting records
To add a new record to a content provider, first set up a
map of key-value pairs in a ContentValues object, where
each key matches the name of a column in the content
provider and the value is the desired value for the new
record in that column. Then call ContentResolver.insert()
and pass it the URI of the provider and the ContentValues
map.
Adding records
Adding new values
Batch updating records
To batch update a group of records (for example, to
change "NY" to "New York" in all fields), call the
ContentResolver.update() method with the columns
and values to change.
Deleting a record
To delete a single record, call
ContentResolver.delete() with the URI of a specific
row.
Set up a system for storing the data. Most content
providers store their data using Android's file storage
methods or SQLite databases, but you can store
your data any way you want. Android provides the
SQLiteOpenHelper class to help you create a
database and SQLiteDatabase to manage it.
Creating a Content Provider
To create a content provider, you must:
Extend the ContentProvider class to provide
access to the data
Declare the content provider in the manifest file
for your application (AndroidManifest.xml).
Extending the ContentProvider class
You define a ContentProvider subclass to expose
your data to others using the conventions expected
by ContentResolver and Cursor objects. Principally,
this means implementing six abstract methods
declared in the ContentProvider class:
Starting an Activity
Define a public static final Uri named CONTENT_URI.
This is the string that represents the full content: URI
that your content provider handles. You must define a
unique string for this value. The best solution is to use
the fully-qualified class name of the content provider
(made lowercase). So, for example, the URI for a
TransportationProvider class could be defined as
follows:
Declaring the content provider
To let the Android system know about the content
provider you've developed, declare it with a
<provider> element in the application's
AndroidManifest.xml file. Content providers that are
not declared in the manifest are not visible to the
Android system
The name attribute is the fully qualified name of the
ContentProvider subclass. The authorities attribute is
the authority part of the content: URI that identifies
the provider.
android content providers

Contenu connexe

Tendances

Android application structure
Android application structureAndroid application structure
Android application structure
Alexey Ustenko
 
Android notification
Android notificationAndroid notification
Android notification
Krazy Koder
 
android activity
android activityandroid activity
android activity
Deepa Rani
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
Krazy Koder
 

Tendances (20)

Android Widget
Android WidgetAndroid Widget
Android Widget
 
Android Services
Android ServicesAndroid Services
Android Services
 
Fragment
Fragment Fragment
Fragment
 
Android Location and Maps
Android Location and MapsAndroid Location and Maps
Android Location and Maps
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Android structure
Android structureAndroid structure
Android structure
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Android notification
Android notificationAndroid notification
Android notification
 
Dvm
DvmDvm
Dvm
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Alarms
AlarmsAlarms
Alarms
 
android activity
android activityandroid activity
android activity
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
Basic android-ppt
Basic android-pptBasic android-ppt
Basic android-ppt
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android resources
Android resourcesAndroid resources
Android resources
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 

Similaire à android 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
Ahsanul Karim
 
Mobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdfMobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdf
AbdullahMunir32
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
AbdullahMunir32
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
application Fundamentals Android Introduction
application Fundamentals  Android Introductionapplication Fundamentals  Android Introduction
application Fundamentals Android Introduction
jeronimored
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
AbdullahMunir32
 

Similaire à android content providers (20)

Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
 
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
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
 
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
 
Custom content provider in android
Custom content provider in androidCustom content provider in android
Custom content provider in android
 
Mobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdfMobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdf
 
"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
 
Chachra, "Improving Discovery Systems Through Post Processing of Harvested Data"
Chachra, "Improving Discovery Systems Through Post Processing of Harvested Data"Chachra, "Improving Discovery Systems Through Post Processing of Harvested Data"
Chachra, "Improving Discovery Systems Through Post Processing of Harvested Data"
 
Cognos Software Development Kit
Cognos Software Development KitCognos Software Development Kit
Cognos Software Development Kit
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
 
Android content providers
Android content providersAndroid content providers
Android content providers
 
application Fundamentals Android Introduction
application Fundamentals  Android Introductionapplication Fundamentals  Android Introduction
application Fundamentals Android Introduction
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
 
Cloud as a GIFT: Exploiting Personal Cloud Free Accounts via Rest APIs
Cloud as a GIFT: Exploiting Personal Cloud Free Accounts via Rest APIsCloud as a GIFT: Exploiting Personal Cloud Free Accounts via Rest APIs
Cloud as a GIFT: Exploiting Personal Cloud Free Accounts via Rest APIs
 
Android App Development - 10 Content providers
Android App Development - 10 Content providersAndroid App Development - 10 Content providers
Android App Development - 10 Content providers
 
Project a twitter dataset analysis
Project a twitter dataset analysisProject a twitter dataset analysis
Project a twitter dataset analysis
 
Beginning android
Beginning android Beginning android
Beginning android
 

Plus de Deepa Rani

Speed controller of dc motor
Speed controller of dc motorSpeed controller of dc motor
Speed controller of dc motor
Deepa Rani
 
Foot step power generator
Foot step power generatorFoot step power generator
Foot step power generator
Deepa Rani
 
Crime investigation system
Crime investigation systemCrime investigation system
Crime investigation system
Deepa Rani
 
android sqlite
android sqliteandroid sqlite
android sqlite
Deepa Rani
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogs
Deepa Rani
 
android layouts
android layoutsandroid layouts
android layouts
Deepa Rani
 
android architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processandroid architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution process
Deepa Rani
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copy
Deepa Rani
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themes
Deepa Rani
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
Deepa Rani
 
Fabric innovation
Fabric innovationFabric innovation
Fabric innovation
Deepa Rani
 
Typical problem
Typical problemTypical problem
Typical problem
Deepa Rani
 
straight line
straight line straight line
straight line
Deepa Rani
 
Section of solids
Section of solidsSection of solids
Section of solids
Deepa Rani
 
Projection of solids
Projection of solidsProjection of solids
Projection of solids
Deepa Rani
 

Plus de Deepa Rani (20)

Speed controller of dc motor
Speed controller of dc motorSpeed controller of dc motor
Speed controller of dc motor
 
Foot step power generator
Foot step power generatorFoot step power generator
Foot step power generator
 
Crime investigation system
Crime investigation systemCrime investigation system
Crime investigation system
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
android menus
android menusandroid menus
android menus
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogs
 
android layouts
android layoutsandroid layouts
android layouts
 
android architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processandroid architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution process
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copy
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themes
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
Blue Brain
Blue BrainBlue Brain
Blue Brain
 
Tcp
TcpTcp
Tcp
 
Dc machiness
Dc machinessDc machiness
Dc machiness
 
Maddy android
Maddy androidMaddy android
Maddy android
 
Fabric innovation
Fabric innovationFabric innovation
Fabric innovation
 
Typical problem
Typical problemTypical problem
Typical problem
 
straight line
straight line straight line
straight line
 
Section of solids
Section of solidsSection of solids
Section of solids
 
Projection of solids
Projection of solidsProjection of solids
Projection of solids
 

Dernier

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

android content providers

  • 1.
  • 2. Content Providers Content providers store and retrieve data and make it accessible to all applications. They're the only way to share data across applications; there's no common storage area that all Android packages can access. Android ships with a number of content providers for common data types (audio, video, images, personal contact information, and so on). You can see some of them listed in the android.provider package.
  • 3. making your own data public If you want to make your own data public, you have two options: You can create your own content provider (a ContentProvider subclass) or you can add the data to an existing provider It's an interface that clients use indirectly, most generally through ContentResolver objects. You get a ContentResolver by calling getContentResolver() from within the implementation of an Activity or other application component:
  • 4. URIs Each 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://". The content: scheme identifies the data as being controlled by a content provider.
  • 6. Modifying Data Data kept by a content provider can be modified by:  Adding new records  Adding new values to existing records  Batch updating existing records  Deleting records
  • 7. To add a new record to a content provider, first set up a map of key-value pairs in a ContentValues object, where each key matches the name of a column in the content provider and the value is the desired value for the new record in that column. Then call ContentResolver.insert() and pass it the URI of the provider and the ContentValues map. Adding records
  • 9. Batch updating records To batch update a group of records (for example, to change "NY" to "New York" in all fields), call the ContentResolver.update() method with the columns and values to change.
  • 10. Deleting a record To delete a single record, call ContentResolver.delete() with the URI of a specific row.
  • 11. Set up a system for storing the data. Most content providers store their data using Android's file storage methods or SQLite databases, but you can store your data any way you want. Android provides the SQLiteOpenHelper class to help you create a database and SQLiteDatabase to manage it. Creating a Content Provider To create a content provider, you must: Extend the ContentProvider class to provide access to the data Declare the content provider in the manifest file for your application (AndroidManifest.xml).
  • 12. Extending the ContentProvider class You define a ContentProvider subclass to expose your data to others using the conventions expected by ContentResolver and Cursor objects. Principally, this means implementing six abstract methods declared in the ContentProvider class:
  • 13. Starting an Activity Define a public static final Uri named CONTENT_URI. This is the string that represents the full content: URI that your content provider handles. You must define a unique string for this value. The best solution is to use the fully-qualified class name of the content provider (made lowercase). So, for example, the URI for a TransportationProvider class could be defined as follows:
  • 14. Declaring the content provider To let the Android system know about the content provider you've developed, declare it with a <provider> element in the application's AndroidManifest.xml file. Content providers that are not declared in the manifest are not visible to the Android system The name attribute is the fully qualified name of the ContentProvider subclass. The authorities attribute is the authority part of the content: URI that identifies the provider.