Android 访问联系人内容提供商
我只是想访问联系人内容提供商。为此,我编写了以下代码Android 访问联系人内容提供商,android,Android,我只是想访问联系人内容提供商。为此,我编写了以下代码 Cursor cur= getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,null,null,null); startManagingCursor(cur); String[] result=new String[cur.getCount()]; if(cur.moveToFirst()) { in
Cursor cur= getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,null,null,null);
startManagingCursor(cur);
String[] result=new String[cur.getCount()];
if(cur.moveToFirst())
{
int nameidx=cur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
int Ididx=cur.getColumnIndexOrThrow(ContactsContract.Contacts._ID);
String strName=cur.getString(nameidx);
String strId=cur.getString(Ididx);
result[cur.getPosition()]=strName+"("+strId+")";
}while(cur.moveToNext());
stopManagingCursor(cur);
}
但是它只显示一个联系人姓名。我想显示所有可用联系人。请告诉我怎么做。试试这个
Cursor cur= getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,null,null,null);
startManagingCursor(cur);
String[] result=new String[cur.getCount()];
for (boolean hasData = cursor.moveToFirst(); hasData; hasData = cursor.moveToNext())
{
int nameidx=cur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
int Ididx=cur.getColumnIndexOrThrow(ContactsContract.Contacts._ID);
String strName=cur.getString(nameidx);
String strId=cur.getString(Ididx);
result[cur.getPosition()]=strName+"("+strId+")";
}
stopManagingCursor(cur);
}
你确定“while”吗?我想问题就在这里你的do声明在哪里?事实上我错过了我的do声明,这就是问题所在。谢谢你告诉我,我可以直接查电话号码吗??????????