android101 - content providers

17
Content Providers Please download and open: http://goo.gl/aDmGsR

Upload: jromero1214

Post on 25-Jun-2015

109 views

Category:

Education


1 download

DESCRIPTION

A glance at Content Providers and how to use them.

TRANSCRIPT

Page 1: Android101 - Content Providers

ContentProvidersPlease download and open: http://goo.gl/aDmGsR

Page 2: Android101 - Content Providers

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

Use Case

Objects

Storage

Page 4: Android101 - Content Providers

Interactions

ContentProvider

Registers

ContentResolverContentResolver

CRUD

CRUD

CRUD

Your AppOther Apps

Platform

Page 5: Android101 - Content Providers

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

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

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

Query (sample)

Page 9: Android101 - Content Providers

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

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

Use Case (people)

Page 12: Android101 - Content Providers

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

URI (sample) authority: our authority is…

com.example.rememberme.provider.PersonContentProvider

path: using table nameperson

Page 14: Android101 - Content Providers

UriMatcher Helper class to match URIs to a specific

integer codes.

UriMatcher (sample)

Page 15: Android101 - Content Providers

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

MIME Types (sample)

Page 17: Android101 - Content Providers

Let’s get coding…