tags:

views:

60

answers:

2
+1  Q: 

Reading contacts

Hi, 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?

+1  A: 

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

Karan
A: 

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

JaVadid