Android获取ArrayList中所有联系人的电话号码

问题描述:

我正在尝试将所有联系人电话号码保存在一个 ArrayList 中,但我找不到方法.有没有办法让它们而不是用 ContactsContract 一个一个地挑选它们?

I am trying to save all contacts telephone numbers in an ArrayList but I cant find a way how. Is there a way to get them instead of picking them one by one with ContactsContract?

试试这个:

Cursor managedCursor = getContentResolver()
    .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
     new String[] {Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER}, null, null,  Phone.DISPLAY_NAME + " ASC");

通过遍历游标,您可以将所有这些数据存储在您选择的任何数据结构中.

And by traversing through the cursor, you can store all this data in any data structure of your choice.