O'Reilly logo

Programming Android by Zigurd Mednieks, G. Blake Meike, Masumi Nakamura, Laird Dornin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Step 4: Implementing the RESTful Request

Step 4 is quite a bit more involved than the other components of the sequence so far. We’ll need to walk through our RESTful FinchVideoContentProvider as we did for SimpleFinchVideoContentProvider. To start, FinchVideoContentProvider extends our utility called RESTfulContentProvider which in turn extends ContentProvider:

FinchVideoContentProvider extend RESTfulContentProvider {

RESTfulContentProvider provides asynchronous REST operations in a way that allows the Finch provider to plug in custom request-response handler components. We’ll explain this in more detail shortly, when we discuss our enhanced query method.

Constants and Initialization

FinchVideoContentProvider initialization is pretty close to the simple video content provider. As with the simple version, we set up a URI matcher. Our only extra task is to add support for matching specific thumbnails. We don’t add support for matching multiple thumbnails, since our viewer activity does not need that support—it only needs to load individual thumbnails:

sUriMatcher.addURI(FinchVideo.AUTHORITY,
    FinchVideo.Videos.THUMB + "/#", THUMB_ID);

Creating the Database

We create the Finch video database with Java code that executes the following SQL:

CREATE TABLE video (_ID INTEGER PRIMARY KEY AUTOINCREMENT, 
    title TEXT, description TEXT, thumb_url TEXT, 
    thumb_width TEXT, thumb_height TEXT, timestamp TEXT,
    query_text TEXT, media_id TEXT UNIQUE);

Note that we’ve added the ability to store the following attributes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required