public void onCreate(Bundle savedInstanceState)
{
TextView tv = new TextView(this);
String string = "";
super.onCreate(savedInstanceState);
//得到ContentResolver對象
ContentResolver cr = getContentResolver();
//取得電話本中開始一項的光標
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
//向下移動一下光標
while(cursor.moveToNext())
{
//取得聯系人名字
int nameFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = cursor.getString(nameFieldColumnIndex);
//取得電話號碼
int numberFieldColumnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
String number = cursor.getString(numberFieldColumnIndex);
string += (contact+":"+number+"\n");
}
cursor.close();
//設置TextView顯示的內容
tv.setText(string);
//顯示到屏幕
setContentView(tv);
}