开发者

Reading contacts

开发者 https://www.devze.com 2022-12-29 17:18 出处:网络
I\'m trying to read all the contacts stored in the phone using this code: Curs开发者_开发百科or cursorNumber =

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

Curs开发者_开发百科or 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?


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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消