A contract describes how the information of the content provider is stored.
It defines:
public static final String CONTENT_AUTHORITY = "com.example.android.sunshine.app";
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
// Data path (appended to base content URI)
public static final String DATA_PATH = "aliasToTableData"; // Generally just the table Name
// For instance, content://com.example.android.sunshine.app/aliasToTableData/ is a valid path for
/* Inner class that defines the table contents of the location table */
public static final class TableEntry implements BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(DATA_PATH).build();
// Content Type: Return more than one entry (a cursor or a dir)
// The content type is returned by the getType(Uri) function of the content provider
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + DATA_PATH;
// Content Type: Return only one row
// The content type is returned by the getType(Uri) function of the content provider
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + DATA_PATH;
// Table name
public static final String TABLE_NAME = "tableName";
// The columns name
public static final String COLUMN_LOCATION_SETTING = "location_setting";
public static final String COLUMN_CITY_NAME = "city_name";
public static final String COLUMN_COORD_LAT = "coord_lat";
public static final String COLUMN_COORD_LONG = "coord_long";
// The URI to return a row by Id
public static Uri buildLocationUri(long id) {
return ContentUris.withAppendedId(CONTENT_URI, id);
}
}