ContentResolver是通过URI来查询ContentProvider中提供的数据。
除了URI以外,还必须知道需要获取的数据段的名称,以及此数据段的数据类型。如果你需要获取一个特定的记录,你就必须知道当前记录的ID,也就是URI中D部分。
前面也提到了Content providers是以类似数据库中表的方式将数据暴露出去,那么ContentResolver也将采用类似数据库的操作来从Content providers中获取数据。
现在简要介绍ContentResolver的主要接口,如下:
返回值 | 函数声明 |
final Uri |
insert(Uri url, ContentValues values)Inserts a row into a table at the given URL. |
final int |
delete(Uri url, String where, String[] selectionArgs)Deletes row(s) specified by a content URI. |
final Cursor |
query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)Query the given URI, returning a Cursor over the result set. |
final int |
update(Uri uri, ContentValues values, String where, String[] selectionArgs)Update row(s) in a content URI. |
最后一个问题:如何获取ContentResolver?调
用getContentResolver (),例如:ContentResolver cr = getContentResolver();