Code example for ContentValues

Methods: containsKeytoString

0
		} 
	} 
 
	@Override 
	public Uri insert(Uri uri, ContentValues values) {
		Log.v(TAG, "insert(), uri=" + uri + ", values=" + values.toString());
 
		// Select which data type to insert 
		switch (uriMatcher.match(uri)) {
		case Schema.URI_CODE_TRACK_TRACKPOINTS:
			// Check that mandatory columns are present. 
			if (values.containsKey(Schema.COL_TRACK_ID) && values.containsKey(Schema.COL_LONGITUDE)
					&& values.containsKey(Schema.COL_LATITUDE) && values.containsKey(Schema.COL_TIMESTAMP)) {
 
				long rowId = dbHelper.getWritableDatabase().insert(Schema.TBL_TRACKPOINT, null, values);
				if (rowId > 0) {
					Uri trackpointUri = ContentUris.withAppendedId(uri, rowId);
					getContext().getContentResolver().notifyChange(trackpointUri, null);
					return trackpointUri;
				} 
			} else { 
				throw new IllegalArgumentException("values should provide " + Schema.COL_LONGITUDE + ", "
						+ Schema.COL_LATITUDE + ", " + Schema.COL_TIMESTAMP);
			} 
			break; 
		case Schema.URI_CODE_TRACK_WAYPOINTS:
			// Check that mandatory columns are present. 
			if (values.containsKey(Schema.COL_TRACK_ID) && values.containsKey(Schema.COL_LONGITUDE)
					&& values.containsKey(Schema.COL_LATITUDE) && values.containsKey(Schema.COL_TIMESTAMP) ) {
 
				long rowId = dbHelper.getWritableDatabase().insert(Schema.TBL_WAYPOINT, null, values);
				if (rowId > 0) {
					Uri waypointUri = ContentUris.withAppendedId(uri, rowId);
					getContext().getContentResolver().notifyChange(waypointUri, null);
					return waypointUri;
				} 
			} else { 
				throw new IllegalArgumentException("values should provide " + Schema.COL_LONGITUDE + ", "
						+ Schema.COL_LATITUDE + ", " + Schema.COL_TIMESTAMP);
			} 
			break; 
		case Schema.URI_CODE_TRACK:
			if (values.containsKey(Schema.COL_START_DATE)) {
				long rowId = dbHelper.getWritableDatabase().insert(Schema.TBL_TRACK, null, values);
				if (rowId > 0) {
					Uri trackUri = ContentUris.withAppendedId(CONTENT_URI_TRACK, rowId);
					getContext().getContentResolver().notifyChange(trackUri, null);
					return trackUri;
				}