SlideShare a Scribd company logo
Android Application Development
Content Provider
Ahsanul Karim
ahsanul.karim@sentinelbd.com
Sentinel Solutions Ltd.
http://www.sentinelbd.com
Application Building Blocks
• UI Component Typically
Corresponding to one screen.
Activity
• Responds to notifications or status
changes. Can wake up your process.
IntentReceiver
• Faceless task that runs in the
background.
Service
• Enable applications to share data.ContentProvider
Android Application Anatomy
Activities
1. Provides User Interface
2. Usually represents a Single Screen
3. Can contain one/more Views
4. Extends the Activity Base class
Services
1. No User Interface
2. Runs in Background
3. Extends the Service Base Class
Application= Set of Android Components
Content Provider
1. Makes application data available
to other apps
2. Data stored in SQLite database
3. Extends the ContentProvider
Base class
Intent/Broadcast Receiver
1. Receives and Reacts to broadcast
Intents
2. No UI but can start an Activity
3. Extends the BroadcastReceiver
Base Class
Android Content Provider
App 1
(Dialer)
App 2
(Messaging)
App 3
(Custom)
App 4
(Custom)
Content Provider 1
Data can be shared over different applications
Content Provider Basics
1. There are no common storage area that all Android application can access.
2. The only way: to share data across applications: Content Provider
3. Content providers store and retrieve data and make it accessible to all
applications.
Content Provider 2
Android Content Provider
Content Provider Basics (Contd.)
Android ships with a number of content providers for common data types:
1. Audio
2. Video
3. Images
4. Personal contact information etc
Content Provider provides the way to share the data between multiple applications.
For example, contact data is used by multiple applications (Dialer, Messaging etc.)
and must be stored in Content Provider to have common access.
A content provider is a class that implements a standard set of methods to let other
applications store and retrieve the type of data that is handled by that content provider.
Content Provider
data
App 1
App 2
Android Content Provider
Content Provider Basics (Contd.)
Here are some of Android's most useful built-in content providers, along with a description of
the type of data they're intended to store
Application can perform following operations on content provider -
1. Querying data
2. Modifying records
3. Adding records
4. Deleting records
Android Content Provider
Querying Data
Content Provider Data Model
Content providers expose their data as a simple table on a database model, where each row
is a record and each column is data of a particular type and meaning.
For example, information about people and their phone numbers might be exposed as follows:
Every record includes a numeric _ID field that uniquely identifies the record within the table.
IDs can be used to match records in related tables — for example, to find a person's phone
number in one table and pictures of that person in another.
A query returns a Cursor object that can move from record to record and column to column
to read the contents of each field. It has specialized methods for reading each type of data.
So, to read a field, you must know what type of data the field contains.
Android Content Provider
Querying Data
Content Provide: URI
1. Each content provider exposes a public URI that uniquely identifies its data set.
2. A content provider that controls multiple data sets (multiple tables) exposes a
separate URI for each one.
3. All URIs for providers begin with the string "content://".
The content: scheme identifies the data as being controlled by a content provider.
URI samples:
<standard_prefix>://<authority>/<data_path>/<id>
For example, to retrieve all the bookmarks stored by our web browsers (in Android):
content://browser/bookmarks
Similarly, to retrieve all the contacts stored by the Contacts application:
content://contacts/people
To retrieve a particular contact, you can specify the URI with a specific ID:
content://contacts/people/3
Android Content Provider
Querying Data
Content Provide: URI
So we need three pieces of information to query a content provider:
1. The URI that identifies the provider
2. The names of the data fields you want to receive
3. The data types for those fields
If we are querying a particular record, you also need the ID for that record.
Some more examples:
content://media/internal/images URI return the list of all internal images on the device.
content://contacts/people/ URI return the list of all contact names on the device.
content://contacts/people/45 URI return the single result row, the contact with ID=45.
Android Content Provider
Querying Data
Content Provide: URI
•Although this is the general form of the query, query URIs are arbitrary and confusing.
•For this android provide list of helper classes in android.provider package that define these
query Strings.
So we do not need to know the actual URI value for different data types.
So it will be easy to query data.
content://media/internal/images/ MediaStore.Images.Media.INTERNAL_CONTENT_URI
content://contacts/people/ Contacts.People.CONTENT_URI
content://contacts/people/45
Uri person = ContentUris.withAppendedId(People.CONTENT_URI, 23);
To query about specific record we have to use same CONTENT_URI and
must append specific ID.
Content Provider: Query
Here is how we can query for data:
Cursor cur = managedQuery(uri, null, null, null);
Android Content Provider
Querying Data
Content Provider: Query
Here is how we can query for data:
Cursor cur = managedQuery(uri, null, null, null, null);
Parameters:
1. URI
2. The names of the data columns that should be returned. A null value returns all
columns.
3. A filter detailing which rows to return, formatted as an SQL WHERE clause
(excluding the WHERE itself). A null value returns all rows.
4. Selection arguments
5. A sorting order for the rows that are returned, formatted as an SQL ORDER
BY clause (excluding the ORDER BY itself). A null value returns the records in the
default order for the table, which may be unordered.
Android Content Provider
Querying Data
Content Provider: Query Example
Create a new project:
Project Name: ContentProviderDemo1
Build Target: Android 1.6
Application Name:
ContentProviderDemo1
Package Name:
com.basistraining.cpdemo
Create Activity:
ContentProviderDemoActivity
Min SDK Version: 4
Add READ_CONTACTS permission
Now we make the Activity a
ListActivity to show a list of contacts
Android Content Provider
Querying Data
Content Provider: Query Example
Now we make the Activity a ListActivity to show a list of contacts:
Now, we’ll add a method to retrieve data from Contacts Content Provider.
The method will return an array of String which will be set as adapter for ListActivity
Android Content Provider
Querying Data Content Provider: Query Example
Now, we’ll add a method to retrieve data from Contacts Content Provider.
The method will return an array of String which will be set as adapter for ListActivity
Android Content Provider
Querying Data Content Provider: Query Example
Now, we need to show data in list:
Android Content Provider
Querying Data Content Provider: Query Example
Now, We run the app and in emulator we see a black screen as the emulator has no contact
data:
Lets add some contacts using Contacts app
Android Content Provider
Querying Data Content Provider: Query Example
If we run the app again:
What we are doing here???
We are accessing the content provider
Contacts from our application.
Contacts application inserts data into Contact
Content Provider.
App 1
(Contacts)
App 2
(our app)
Contacts Content Provider
Android Content Provider
Modifying Data Content Provider: Update Example
Let’s add another Activity which will load with selected data and provide us interface to edit:
1. We create Update Activity
2. We modify the main.xml for updating
Android Content Provider
Modifying Data Content Provider: Update Example
Let’s get back to ListActivity:
1. To identify which data to be updated we’ll need to pass _ID of the selected Person. So we
Modify the columns
2. We need to save the values in global arrays to pass them as parameter to update screen.
So:
Android Content Provider
Modifying Data Content Provider: Update Example
We need to save the values in global arrays to pass them as parameter to update screen.
So:
Android Content Provider
Modifying Data Content Provider: Update Example
Now we detect selected person and pass the values to Update screen:
And in the UpdateActivity, we get the values and set them in UI:
Android Content Provider
Modifying Data Content Provider: Update Example
Now lets add button functionality of Update
Need the method updateName()
Android Content Provider
Modifying Data Content Provider: Update Example
Now lets run the app and we end up with:
WHY????
Android Content Provider
Modifying Data Content Provider: Update Example
Now lets run the app and we end up with:
We need to add WRITE_CONTACTS permission
Android Content Provider
Modifying Data Content Provider: Update Example
Now follow the steps for testing:
1. Run the app
2. Select a Contact
3. Edit Contact name
4. Go back to main screen
5. Exit app
6. Check whether data is updated from the Contacts app
Android Content Provider
Practice Exercise
1. Create an Application named “Bookmark Manager”
2. In AVD, browse several sites in browser and bookmark them
3. Read all bookmarks from browser Content Provider and show them in list
4. On selecting an URL go to a new activity and open that link in a webview
Hints
URI: android.provider.Browser.BOOKMARKS_URI
Fields:
1. Browser.BookmarkColumns._ID,
2. Browser.BookmarkColumns.TITLE,
3. Browser.BookmarkColumns.URL
Ad

More Related Content

What's hot (20)

Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgets
Prajyot Mainkar
 
Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
vishal choudhary
 
Android content provider explained
Android content provider explainedAndroid content provider explained
Android content provider explained
Shady Selim
 
Android Services and Managers Basic
Android Services and Managers BasicAndroid Services and Managers Basic
Android Services and Managers Basic
William Lee
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
vishal choudhary
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
vishal choudhary
 
Android Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptxAndroid Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptx
vishal choudhary
 
Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection Widget
Prajyot Mainkar
 
Building a YellowAnt Application with Ruby on Rails
Building a YellowAnt Application with Ruby on RailsBuilding a YellowAnt Application with Ruby on Rails
Building a YellowAnt Application with Ruby on Rails
Jaya Jain
 
Lab2-android
Lab2-androidLab2-android
Lab2-android
Lilia Sfaxi
 
Android Widget
Android WidgetAndroid Widget
Android Widget
ELLURU Kalyan
 
Android appwidget
Android appwidgetAndroid appwidget
Android appwidget
Krazy Koder
 
Building a YellowAnt application with .NET
Building a YellowAnt application with .NETBuilding a YellowAnt application with .NET
Building a YellowAnt application with .NET
Vishwa Krishnakumar
 
Murach: How to transfer data from controllers
Murach: How to transfer data from controllersMurach: How to transfer data from controllers
Murach: How to transfer data from controllers
MahmoudOHassouna
 
Murach: How to use Entity Framework EF Core
Murach: How to use Entity Framework EF  CoreMurach: How to use Entity Framework EF  Core
Murach: How to use Entity Framework EF Core
MahmoudOHassouna
 
List Views
List ViewsList Views
List Views
Ahsanul Karim
 
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
MahmoudOHassouna
 
Murach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routingMurach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routing
MahmoudOHassouna
 
Murach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVCMurach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVC
MahmoudOHassouna
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
MahmoudOHassouna
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgets
Prajyot Mainkar
 
Create an android app for database creation using.pptx
Create an android app for database creation using.pptxCreate an android app for database creation using.pptx
Create an android app for database creation using.pptx
vishal choudhary
 
Android content provider explained
Android content provider explainedAndroid content provider explained
Android content provider explained
Shady Selim
 
Android Services and Managers Basic
Android Services and Managers BasicAndroid Services and Managers Basic
Android Services and Managers Basic
William Lee
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
vishal choudhary
 
Android Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptxAndroid Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptx
vishal choudhary
 
Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection Widget
Prajyot Mainkar
 
Building a YellowAnt Application with Ruby on Rails
Building a YellowAnt Application with Ruby on RailsBuilding a YellowAnt Application with Ruby on Rails
Building a YellowAnt Application with Ruby on Rails
Jaya Jain
 
Android appwidget
Android appwidgetAndroid appwidget
Android appwidget
Krazy Koder
 
Building a YellowAnt application with .NET
Building a YellowAnt application with .NETBuilding a YellowAnt application with .NET
Building a YellowAnt application with .NET
Vishwa Krishnakumar
 
Murach: How to transfer data from controllers
Murach: How to transfer data from controllersMurach: How to transfer data from controllers
Murach: How to transfer data from controllers
MahmoudOHassouna
 
Murach: How to use Entity Framework EF Core
Murach: How to use Entity Framework EF  CoreMurach: How to use Entity Framework EF  Core
Murach: How to use Entity Framework EF Core
MahmoudOHassouna
 
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
MahmoudOHassouna
 
Murach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routingMurach : HOW to work with controllers and routing
Murach : HOW to work with controllers and routing
MahmoudOHassouna
 
Murach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVCMurach: An introduction to web programming with ASP.NET Core MVC
Murach: An introduction to web programming with ASP.NET Core MVC
MahmoudOHassouna
 
Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
MahmoudOHassouna
 

Viewers also liked (18)

Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS Tutorial
Ahsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
Ahsanul Karim
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)
Ahsanul Karim
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
Ahsanul Karim
 
Training android
Training androidTraining android
Training android
University of Technology
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)
Ahsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
Ahsanul Karim
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location API
Ahsanul Karim
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
Ahsanul Karim
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
Ahsanul Karim
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
Parinita03
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
Ahsanul Karim
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overview
Ahsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
Ahsanul Karim
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting started
Ahsanul Karim
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting Started
Ahsanul Karim
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
Ahsanul Karim
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
Ahsanul Karim
 
Android GPS Tutorial
Android GPS TutorialAndroid GPS Tutorial
Android GPS Tutorial
Ahsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
Ahsanul Karim
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)
Ahsanul Karim
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
Ahsanul Karim
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)
Ahsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
Ahsanul Karim
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location API
Ahsanul Karim
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
Ahsanul Karim
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
Ahsanul Karim
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
Parinita03
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overview
Ahsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
Ahsanul Karim
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting started
Ahsanul Karim
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting Started
Ahsanul Karim
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
Ahsanul Karim
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
Ahsanul Karim
 
Ad

Similar to Day 15: Content Provider: Using Contacts API (20)

Custom content provider in android
Custom content provider in androidCustom content provider in android
Custom content provider in android
Aly Arman
 
Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
Khaled Anaqwa
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_android
PRITI TELMORE
 
Mobile application Development-UNIT-V (1).pptx
Mobile application Development-UNIT-V (1).pptxMobile application Development-UNIT-V (1).pptx
Mobile application Development-UNIT-V (1).pptx
JayasimhaThummala1
 
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
 
Android App To Display Employee Details
Android App To Display Employee DetailsAndroid App To Display Employee Details
Android App To Display Employee Details
Saikrishna Tanguturu
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Android Training Session 1
Android Training Session 1Android Training Session 1
Android Training Session 1
Shanmugapriya D
 
Content provider
Content providerContent provider
Content provider
maamir farooq
 
Android resources in android-chapter9
Android resources in android-chapter9Android resources in android-chapter9
Android resources in android-chapter9
Dr. Ramkumar Lakshminarayanan
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
Vivek Bhusal
 
Lec-3-Mobile Application Development.pptx
Lec-3-Mobile Application Development.pptxLec-3-Mobile Application Development.pptx
Lec-3-Mobile Application Development.pptx
SheharBano86
 
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
 
Android Basic- CMC
Android Basic- CMCAndroid Basic- CMC
Android Basic- CMC
Pragati Singh
 
android content providers
android content providersandroid content providers
android content providers
Deepa Rani
 
Android list view tutorial by Javatechig
Android list view tutorial by JavatechigAndroid list view tutorial by Javatechig
Android list view tutorial by Javatechig
Javatechig Resources for Developers
 
Show loader to open url in web view
Show loader to open url in web viewShow loader to open url in web view
Show loader to open url in web view
Aravindharamanan S
 
Sentiment Analysis on Twitter Data Using Apache Flume and Hive
Sentiment Analysis on Twitter Data Using Apache Flume and HiveSentiment Analysis on Twitter Data Using Apache Flume and Hive
Sentiment Analysis on Twitter Data Using Apache Flume and Hive
IRJET Journal
 
Session 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdfSession 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdf
EngmohammedAlzared
 
Custom content provider in android
Custom content provider in androidCustom content provider in android
Custom content provider in android
Aly Arman
 
Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
Khaled Anaqwa
 
Content provider in_android
Content provider in_androidContent provider in_android
Content provider in_android
PRITI TELMORE
 
Mobile application Development-UNIT-V (1).pptx
Mobile application Development-UNIT-V (1).pptxMobile application Development-UNIT-V (1).pptx
Mobile application Development-UNIT-V (1).pptx
JayasimhaThummala1
 
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
 
Android App To Display Employee Details
Android App To Display Employee DetailsAndroid App To Display Employee Details
Android App To Display Employee Details
Saikrishna Tanguturu
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Android Training Session 1
Android Training Session 1Android Training Session 1
Android Training Session 1
Shanmugapriya D
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
Vivek Bhusal
 
Lec-3-Mobile Application Development.pptx
Lec-3-Mobile Application Development.pptxLec-3-Mobile Application Development.pptx
Lec-3-Mobile Application Development.pptx
SheharBano86
 
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
 
android content providers
android content providersandroid content providers
android content providers
Deepa Rani
 
Show loader to open url in web view
Show loader to open url in web viewShow loader to open url in web view
Show loader to open url in web view
Aravindharamanan S
 
Sentiment Analysis on Twitter Data Using Apache Flume and Hive
Sentiment Analysis on Twitter Data Using Apache Flume and HiveSentiment Analysis on Twitter Data Using Apache Flume and Hive
Sentiment Analysis on Twitter Data Using Apache Flume and Hive
IRJET Journal
 
Session 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdfSession 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdf
EngmohammedAlzared
 
Ad

More from Ahsanul Karim (13)

Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
Ahsanul Karim
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick Overview
Ahsanul Karim
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:
Ahsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
Ahsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
Ahsanul Karim
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
Ahsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
Ahsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
Ahsanul Karim
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete Study
Ahsanul Karim
 
GCM for Android
GCM for AndroidGCM for Android
GCM for Android
Ahsanul Karim
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
Ahsanul Karim
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
Ahsanul Karim
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
Ahsanul Karim
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick Overview
Ahsanul Karim
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:
Ahsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
Ahsanul Karim
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
Ahsanul Karim
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
Ahsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
Ahsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
Ahsanul Karim
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete Study
Ahsanul Karim
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
Ahsanul Karim
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
Ahsanul Karim
 

Recently uploaded (20)

HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 

Day 15: Content Provider: Using Contacts API

  • 1. Android Application Development Content Provider Ahsanul Karim [email protected] Sentinel Solutions Ltd. http://www.sentinelbd.com
  • 2. Application Building Blocks • UI Component Typically Corresponding to one screen. Activity • Responds to notifications or status changes. Can wake up your process. IntentReceiver • Faceless task that runs in the background. Service • Enable applications to share data.ContentProvider
  • 3. Android Application Anatomy Activities 1. Provides User Interface 2. Usually represents a Single Screen 3. Can contain one/more Views 4. Extends the Activity Base class Services 1. No User Interface 2. Runs in Background 3. Extends the Service Base Class Application= Set of Android Components Content Provider 1. Makes application data available to other apps 2. Data stored in SQLite database 3. Extends the ContentProvider Base class Intent/Broadcast Receiver 1. Receives and Reacts to broadcast Intents 2. No UI but can start an Activity 3. Extends the BroadcastReceiver Base Class
  • 4. Android Content Provider App 1 (Dialer) App 2 (Messaging) App 3 (Custom) App 4 (Custom) Content Provider 1 Data can be shared over different applications Content Provider Basics 1. There are no common storage area that all Android application can access. 2. The only way: to share data across applications: Content Provider 3. Content providers store and retrieve data and make it accessible to all applications. Content Provider 2
  • 5. Android Content Provider Content Provider Basics (Contd.) Android ships with a number of content providers for common data types: 1. Audio 2. Video 3. Images 4. Personal contact information etc Content Provider provides the way to share the data between multiple applications. For example, contact data is used by multiple applications (Dialer, Messaging etc.) and must be stored in Content Provider to have common access. A content provider is a class that implements a standard set of methods to let other applications store and retrieve the type of data that is handled by that content provider. Content Provider data App 1 App 2
  • 6. Android Content Provider Content Provider Basics (Contd.) Here are some of Android's most useful built-in content providers, along with a description of the type of data they're intended to store Application can perform following operations on content provider - 1. Querying data 2. Modifying records 3. Adding records 4. Deleting records
  • 7. Android Content Provider Querying Data Content Provider Data Model Content providers expose their data as a simple table on a database model, where each row is a record and each column is data of a particular type and meaning. For example, information about people and their phone numbers might be exposed as follows: Every record includes a numeric _ID field that uniquely identifies the record within the table. IDs can be used to match records in related tables — for example, to find a person's phone number in one table and pictures of that person in another. A query returns a Cursor object that can move from record to record and column to column to read the contents of each field. It has specialized methods for reading each type of data. So, to read a field, you must know what type of data the field contains.
  • 8. Android Content Provider Querying Data Content Provide: URI 1. Each content provider exposes a public URI that uniquely identifies its data set. 2. A content provider that controls multiple data sets (multiple tables) exposes a separate URI for each one. 3. All URIs for providers begin with the string "content://". The content: scheme identifies the data as being controlled by a content provider. URI samples: <standard_prefix>://<authority>/<data_path>/<id> For example, to retrieve all the bookmarks stored by our web browsers (in Android): content://browser/bookmarks Similarly, to retrieve all the contacts stored by the Contacts application: content://contacts/people To retrieve a particular contact, you can specify the URI with a specific ID: content://contacts/people/3
  • 9. Android Content Provider Querying Data Content Provide: URI So we need three pieces of information to query a content provider: 1. The URI that identifies the provider 2. The names of the data fields you want to receive 3. The data types for those fields If we are querying a particular record, you also need the ID for that record. Some more examples: content://media/internal/images URI return the list of all internal images on the device. content://contacts/people/ URI return the list of all contact names on the device. content://contacts/people/45 URI return the single result row, the contact with ID=45.
  • 10. Android Content Provider Querying Data Content Provide: URI •Although this is the general form of the query, query URIs are arbitrary and confusing. •For this android provide list of helper classes in android.provider package that define these query Strings. So we do not need to know the actual URI value for different data types. So it will be easy to query data. content://media/internal/images/ MediaStore.Images.Media.INTERNAL_CONTENT_URI content://contacts/people/ Contacts.People.CONTENT_URI content://contacts/people/45 Uri person = ContentUris.withAppendedId(People.CONTENT_URI, 23); To query about specific record we have to use same CONTENT_URI and must append specific ID. Content Provider: Query Here is how we can query for data: Cursor cur = managedQuery(uri, null, null, null);
  • 11. Android Content Provider Querying Data Content Provider: Query Here is how we can query for data: Cursor cur = managedQuery(uri, null, null, null, null); Parameters: 1. URI 2. The names of the data columns that should be returned. A null value returns all columns. 3. A filter detailing which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). A null value returns all rows. 4. Selection arguments 5. A sorting order for the rows that are returned, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). A null value returns the records in the default order for the table, which may be unordered.
  • 12. Android Content Provider Querying Data Content Provider: Query Example Create a new project: Project Name: ContentProviderDemo1 Build Target: Android 1.6 Application Name: ContentProviderDemo1 Package Name: com.basistraining.cpdemo Create Activity: ContentProviderDemoActivity Min SDK Version: 4 Add READ_CONTACTS permission Now we make the Activity a ListActivity to show a list of contacts
  • 13. Android Content Provider Querying Data Content Provider: Query Example Now we make the Activity a ListActivity to show a list of contacts: Now, we’ll add a method to retrieve data from Contacts Content Provider. The method will return an array of String which will be set as adapter for ListActivity
  • 14. Android Content Provider Querying Data Content Provider: Query Example Now, we’ll add a method to retrieve data from Contacts Content Provider. The method will return an array of String which will be set as adapter for ListActivity
  • 15. Android Content Provider Querying Data Content Provider: Query Example Now, we need to show data in list:
  • 16. Android Content Provider Querying Data Content Provider: Query Example Now, We run the app and in emulator we see a black screen as the emulator has no contact data: Lets add some contacts using Contacts app
  • 17. Android Content Provider Querying Data Content Provider: Query Example If we run the app again: What we are doing here??? We are accessing the content provider Contacts from our application. Contacts application inserts data into Contact Content Provider. App 1 (Contacts) App 2 (our app) Contacts Content Provider
  • 18. Android Content Provider Modifying Data Content Provider: Update Example Let’s add another Activity which will load with selected data and provide us interface to edit: 1. We create Update Activity 2. We modify the main.xml for updating
  • 19. Android Content Provider Modifying Data Content Provider: Update Example Let’s get back to ListActivity: 1. To identify which data to be updated we’ll need to pass _ID of the selected Person. So we Modify the columns 2. We need to save the values in global arrays to pass them as parameter to update screen. So:
  • 20. Android Content Provider Modifying Data Content Provider: Update Example We need to save the values in global arrays to pass them as parameter to update screen. So:
  • 21. Android Content Provider Modifying Data Content Provider: Update Example Now we detect selected person and pass the values to Update screen: And in the UpdateActivity, we get the values and set them in UI:
  • 22. Android Content Provider Modifying Data Content Provider: Update Example Now lets add button functionality of Update Need the method updateName()
  • 23. Android Content Provider Modifying Data Content Provider: Update Example Now lets run the app and we end up with: WHY????
  • 24. Android Content Provider Modifying Data Content Provider: Update Example Now lets run the app and we end up with: We need to add WRITE_CONTACTS permission
  • 25. Android Content Provider Modifying Data Content Provider: Update Example Now follow the steps for testing: 1. Run the app 2. Select a Contact 3. Edit Contact name 4. Go back to main screen 5. Exit app 6. Check whether data is updated from the Contacts app
  • 26. Android Content Provider Practice Exercise 1. Create an Application named “Bookmark Manager” 2. In AVD, browse several sites in browser and bookmark them 3. Read all bookmarks from browser Content Provider and show them in list 4. On selecting an URL go to a new activity and open that link in a webview Hints URI: android.provider.Browser.BOOKMARKS_URI Fields: 1. Browser.BookmarkColumns._ID, 2. Browser.BookmarkColumns.TITLE, 3. Browser.BookmarkColumns.URL