Code example for Uri

Methods: getPathSegments

0
 
    @Override 
    public int update(Uri uri, ContentValues values, String where,
                      String[] whereArgs)
    { 
        getContext().getContentResolver().notifyChange(uri, null);
 
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        int count;
        switch (sUriMatcher.match(uri)) {
            case VIDEOS:
                count = db.update(VIDEOS_TABLE_NAME, values, where, whereArgs);
                break; 
 
            case VIDEO_ID:
                String videoId = uri.getPathSegments().get(1);
                count = db.update(VIDEOS_TABLE_NAME, values,
                        BaseColumns._ID + "=" + videoId
                                + (!TextUtils.isEmpty(where) ?
                                " AND (" + where + ')' : ""),
                        whereArgs);
                break; 
 
            default: 
                throw new IllegalArgumentException("Unknown URI " + uri);
        } 
 
        getContext().getContentResolver().notifyChange(uri, null);
        return count;
    } 
}