开发者

Accessing the contact Content Provider

I am just tring to access the contact Content Provider. for that i wrote following code

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.getColumnIndexOrTh开发者_如何学JAVArow(ContactsContract.Contacts._ID);
        String strName=cur.getString(nameidx);
        String strId=cur.getString(Ididx);

        result[cur.getPosition()]=strName+"("+strId+")";
    }while(cur.moveToNext());

   stopManagingCursor(cur);
}

but its showing only one contact name i want to show all contact available please tell me how do that.


try this instead

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜