Reading contacts

I am trying to read all the contacts stored in the phone using this code:

Cursor cursorNumber = context.getContentResolver (). query (Contacts.Phones.CONTENT_URI, new line [] {Contacts.Phones._ID, Contacts.Phones.NAME, Contacts.Phones.NUMBER}, null, null, null);

but the result seems to be empty until the synchronization of contacts with Google. Is it possible? Is this a limitation of the Google Contacts API?

+3
source share
3 answers

You are using old contact APIs. Try using ContactsContract .

+2
source
cname = managedQuery(People.CONTENT_URI, null, null, null, null);
String[] from = new String[] {People.NAME};
int[] to = new int[] { R.id.text_view };
      SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.contactlist,cname,from,to);
      lv = (ListView)findViewById(R.id.list_view);
      lv.setAdapter(adapter);

      if (cname.moveToFirst()) {
          String name = cname.getString(cname.getColumnIndexOrThrow(People.NAME));
          System.out.println("@@@@@ name" + name);
      }
    if (cname.moveToFirst()) {
        String name = cname.getString(cname.getColumnIndexOrThrow(People.NAME));
        System.out.println("@@@@@ name" + name);
    }
0
source

Source: https://habr.com/ru/post/1744890/


All Articles