记得2.0以后联系人电话号码的查找方法改变了,第一次运行 揭秘 的源代码时也是出错,后来自己找了下,把自己修改过的代码记下来。 package android.text; import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.PhoneLookup; import android.util.Log; import android.widget.TextView; public class CopyContacts02 extends Activity { /** Called when the activity is first created. */ private final static String s = "CopyContacts"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); String string = ""; setContentView(R.layout.main); //得到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 name = cursor.getString(nameFieldColumnIndex); // 取得联系人ID String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); Cursor phone = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); while(phone.moveToNext()){ //取得联系人的号码 int numberIndex = phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); String number = phone.getString(numberIndex); Log.v(s, "GET CONTACT'S NUMBER"); string += (name+":"+number+"/n"); } phone.close(); } cursor.close(); //设置TextView显示的内容 tv.setText(string); //显示到屏幕 setContentView(tv); } }