How to read contacts on Android 2.0

前端 未结 9 952
我寻月下人不归
我寻月下人不归 2020-11-22 05:58

I\'m working on Android 2.0 and am trying to receive a list of all contacts.

Since android.provider.Contacts.People is deprecated, I have to use android

9条回答
  •  清酒与你
    2020-11-22 06:10

    I'm using Samsung Galaxy Note 4, and I donno why none of the above worked for me. I mixed up some and made this woking..

        Cursor people = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
        people.moveToFirst();
        while(people.moveToNext()) {
           int nameFieldColumnIndex = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
           String contact = people.getString(nameFieldColumnIndex);
           int numberFieldColumnIndex = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA);
           String number = people.getString(numberFieldColumnIndex);
           dbWriter.execSQL("Insert Into ContactsList (ContactName, ContactNumber) Values (" +
                     "'" + contact.replace("'",  "''") + "', '" + number.replace("'",  "''") + "')");
        }
        people.close();
    

提交回复
热议问题