简体   繁体   English

阅读联系人

[英]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 ); 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. 但是直到我将联系人与Google同步时,结果才显得空白。 Is that possible? 那可能吗? Is it a limitation of Google Contacts API? 这是Google Contacts API的限制吗?

You are using the old Contact APIs. 您正在使用旧的Contact API。 Try using ContactsContract . 尝试使用ContactsContract

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

有关使用新contactscontract api的示例,您可以访问http://code.google.com/p/android-contacts-contract-example/ ,其中查询所有联系人和信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM