android101 - content providers
DESCRIPTION
A glance at Content Providers and how to use them.TRANSCRIPT
![Page 1: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/1.jpg)
ContentProvidersPlease download and open: http://goo.gl/aDmGsR
![Page 2: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/2.jpg)
ContentProvider Manages data Can use almost any storage option
SQLite File API …
Provides consistent interface (CRUD) Can be restricted with permissions
extends ContentProvider class
![Page 3: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/3.jpg)
Use Case
Objects
Storage
![Page 4: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/4.jpg)
Interactions
ContentProvider
Registers
ContentResolverContentResolver
CRUD
CRUD
CRUD
Your AppOther Apps
Platform
![Page 5: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/5.jpg)
CRUDMethod
Usage
insert Inserts one object. The URI must be directory-based
query Queries for all objects that fit the URI.
update Updates one or all object(s)
delete Deletes the object(s) for the URI provided.
![Page 6: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/6.jpg)
Insert (Create)Type Name Usage
URI uri The URI of the object(s) to access.
ContentValues values The values for the object to add.
![Page 7: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/7.jpg)
Query (Read)Type Name Usage
URI uri The URI of the object(s) to access.
String[]
projection This String array indicates which columns/attributes of the objects you want to access
String selection With this argument you can determine which records to return
String[]
selectionArgs
The binding parameters to the previous selection argument
String sortOrder If the result should be ordered you must use this argument to determine the sort order
![Page 8: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/8.jpg)
Query (sample)
![Page 9: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/9.jpg)
Update(Update)Type Name Usage
URI uri The URI of the object(s) to access.
ContentValues values The values for the object to add.
String selection With this argument you can determine which records to affect
String[] selectionArgs
The binding parameters to the previous selection argument
![Page 10: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/10.jpg)
Delete(Delete)Type Name Usage
URI uri The URI of the object(s) to access.
String selection With this argument you can determine which records to affect
String[] selectionArgs
The binding parameters to the previous selection argument
![Page 11: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/11.jpg)
Use Case (people)
![Page 12: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/12.jpg)
URI content://authority/path/id
authority: is Java namespace of the content provider implementation. (fully qualified Java package name)
path: is the virtual directory within the provider that identifies the kind of data being requested.
id: is optional part that specifies the primary key of a record being requested. We can omit this part to request all records.
![Page 13: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/13.jpg)
URI (sample) authority: our authority is…
com.example.rememberme.provider.PersonContentProvider
path: using table nameperson
![Page 14: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/14.jpg)
UriMatcher Helper class to match URIs to a specific
integer codes.
UriMatcher (sample)
![Page 15: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/15.jpg)
MIME Types Used to determine supported object
types Prefixed with:
vnd.android.cursor.item Single item
vnd.android.cursor.dir List of items
![Page 16: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/16.jpg)
MIME Types (sample)
![Page 17: Android101 - Content Providers](https://reader036.vdocuments.us/reader036/viewer/2022083002/558bcd8bd8b42a960b8b45e3/html5/thumbnails/17.jpg)
Let’s get coding…