Emanuele
Emanuele

Reputation: 31

Reading contacts

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

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

but the result seems empty until the moment I sync the contacts with Google. Is that possible? Is it a limitation of Google Contacts API?

Upvotes: 3

Views: 1303

Answers (3)

JaVadid
JaVadid

Reputation: 7117

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

Upvotes: 0

senola
senola

Reputation: 782

for an example using the new contactscontract api you can visit http://code.google.com/p/android-contacts-contract-example/ where all contacts and information is queried

Upvotes: 0

Karan
Karan

Reputation: 12782

You are using the old Contact APIs. Try using ContactsContract.

Upvotes: 2

Related Questions