Android Tutorial

(avery) #1
Android Tutorial 341

The delete() method deletes all rows at a given URI filtered by the
selection parameters, which, in this case, includes all rows at the
People.CONTENT_URI location; in other words, all contact entries.

Deleting Specific Records

Often you want to select specific rows to delete by adding the
unique identifier index to the end of the URI or remove rows
matching a particular pattern.

For example, the following deletion matches all contact records
with the name Sample User, which we used when we created
sample contacts previously in the chapter.

int rows = getContentResolver().delete(People.CONTENT_URI,
People.NAME + “=?”, new String[] {“Sample User”});
Log.d(debugTag, “Rows: “+ rows);


Enhancing Applications Using Content Providers

The concept of a content provider is complex and best understood
by working through an example. The Pet Tracker series of
applications from the previous chapter are nice and all, but the
application could really use some graphics. Wouldn’t it be great if
we could include photos for each pet record? Well, let’s do it!
There’s only one catch: We need to access pictures provided
through another application on the Android system—the Media
Store application.

In Figure, you can see the results of extending the previous Pet
Tracking projects using the Media Store content provider.
Free download pdf