Android本地的Content Provider
2010-09-27 01:53:00 来源:WEB开发网核心提示:// Let the activity manage the cursor lifecycle.startManagingCursor(cursor);// Use the convenience properties to get the index of the columnsint nameIdx = curso
// Let the activity manage the cursor lifecycle.
startManagingCursor(cursor);
// Use the convenience properties to get the index of the columns
int nameIdx = cursor.getColumnIndexOrThrow(People.NAME);
int phoneIdx = cursor. getColumnIndexOrThrow(People.NUMBER);
String[] result = new String[cursor.getCount()];
if (cursor.moveToFirst())
do {
// Extract the name.
String name = cursor.getString(nameIdx);
// Extract the phone number.
String phone = cursor.getString(phoneIdx);
result[cursor.getPosition()] = name + “ (“ + phone + “)”;
} while(cursor.moveToNext());
为了运行这个代码片段,你需要给程序添加READ_CONTACTS权限。
和查询联系人数据库一样,你还可以使用这个Content Provider来修改、删除或插入联系人记录。
[]
更多精彩
赞助商链接