我正在尝试将所有联系人存储在一个String
数组中,但由于以下错误,它没有获取所有联系人:
I/Choreographer:跳过了 213 帧!应用程序可能在其主线程上做了太多工作。
Java 代码
private void getContactList() {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if ((cur != null ? cur.getCount() : 0) > 0) {
progressDialog.show();
while (cur != null && cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME));
if (cur.getInt(cur.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
// Log.i("tag", "Name: " + name);
// Log.i("tag", "Phone Number: " + phoneNo);
myname += name + ",";
mynumber += phoneNo + ",";
}
pCur.close();
if (progressDialog.isShowing())
progressDialog.dismiss();
}
}
Log.i("tag", "Name: " + myname + mynumber);
}
if (cur != null) {
cur.close();
}
}