【发布时间】:2012-02-09 06:04:01
【问题描述】:
我正在尝试获取所有有电话号码的联系人,并记录他们的全名和电话号码(以及将来他们的联系人照片),但我被卡住了。这是我的代码:
String contacts = "";
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone == "1") {
contacts += cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + ":" + "how to get number?" + "|";
}
}
cursor.close();
如果联系人有电话号码,则字符串 hasPhone 应包含“1”,然后将该姓名和人员电话号码添加到“联系人”字符串中。即使 hasPhone 确实包含“1”,(从 logcat 检查)条件语句中的代码也不会运行。还有,你是怎么得到电话号码的,ContactsContract.Contacts里没有号码。
【问题讨论】:
-
看一下可能对你有用检查stackoverflow.com/questions/12026173/…
标签: java android cursor android-contacts phone-number