【问题标题】:Unable to fetch all the contacts from Android无法从 Android 获取所有联系人
【发布时间】:2015-05-23 13:06:35
【问题描述】:

我需要获取 android 设备上的所有联系人。但是当我使用contentResolver 查询时,我只得到新创建的联系人。即使设备上有多个联系人。下面是我用来获取联系人的查询。光标不会全部返回。

我还观察到一件事。如果我去编辑未获取的联系人,则获取该特定联系人。帮我找到所有的联系人。我错过了什么吗?

String[] projection = new String[] { Contacts.LOOKUP_KEY };
            Cursor people = mContext.getContentResolver().query(Contacts.CONTENT_URI, projection, null, null, null);

【问题讨论】:

  • 找到解决方案的运气..??我遇到了同样的问题。

标签: android cursor android-contacts android-contentresolver


【解决方案1】:

试试这个。

public class ContactActivity extends Activity {

Cursor cursor;
ArrayList<String> NameList=new ArrayList<String>();
ArrayList<String> PhoneList=new ArrayList<String>();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

            cursor = getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);

    while (cursor.moveToNext()) {
        int nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);   
        int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);

        String name = cursor.getString(nameIdx);
        String phone = cursor.getString(phoneNumberIdx);    
        NameList.add(name);
        PhoneList.add(phone);

        System.out.println("Name is :"+name +" number is : "+phone);
        System.out.println("Name is :"+name +" number is : "+phone);
        System.out.println("Name is :"+name +" number is : "+phone);



    }


}
}

【讨论】:

    猜你喜欢
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多