Android content provider基础与使用
2010-08-21 06:22:00 来源:WEB开发网ContentResolver cr = getContentResolver();
//Cursor cur = managedQuery(People.CONTENT_URI, null, null, null, null);
Cursor cur = cr.query(People.CONTENT_URI, null, null, null, null);
getColumnData(cur);
}
private void getColumnData(Cursor cur){
if (cur.moveToFirst()) {
String name;
String phoneNumber;
int nameColumn = cur.getColumnIndex(People.NAME);
int phoneColumn = cur.getColumnIndex(People.NUMBER);
do {
// Get the field values
name = cur.getString(nameColumn);
phoneNumber = cur.getString(phoneColumn);
Log.i(TAG, "name="+name);
DisplayToast(name+" "+phoneNumber);
} while (cur.moveToNext());
}
}
public void DisplayToast(String s)
{
Toast.makeText(this,
s,
Toast.LENGTH_LONG).show();
}
}
需要注意的是,你需要在你的Manifest文件中加上
< uses-permission
android:name="android.permission.READ_CONTACTS">
< /uses-permission>
否则,程序无法成功运行。
更多精彩
赞助商链接