Android Tutorial

(avery) #1

By : Ketan Bhimani


356 

without a specific selection enables deletion of a specified identifier
without having to also know exactly where it came from.

As before, the system is then notified of this change with a call to
the notifyChange() method of ContentResolver. Also as before, the
number of affect rows is returned, which we stored after the call to
the delete() method.

Implementing the getType() Method

The last method to implement is the getType() method. The
purpose of this method is to return the MIME type for a particular
Uri that is passed in. It does not need to return MIME types for
specific columns of data.

public static final String CONTENT_ITEM_TYPE =
ContentResolver.CURSOR_ITEM_BASE_TYPE + “/track-points”;
public static final String CONTENT_TYPE =
ContentResolver.CURSOR_DIR_BASE_TYPE + “/track-points”;
public String getType(Uri uri) {
int matchType = sURIMatcher.match(uri);
switch (matchType) {
case TRACKPOINTS:
return CONTENT_TYPE;
case TRACKPOINT_ID:
return CONTENT_ITEM_TYPE;
default:
throw new
IllegalArgumentException(“Unknown or Invalid URI “ + uri);
}
}


To start, a couple of MIME types are defined. The Android SDK
provides some guideline values for single items and directories of
items, which are used here. The corresponding string for each is
vnd.android.cursor.item and vnd.android.cursor.dir, respectively.
Finally, the match() method is used to determine the type of the
provided Uri so that the appropriate MIME type can bereturned.
Free download pdf