Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2028491
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: LINUX

2010-08-06 14:02:59

  1. Documents
    http://developer.android.com/reference/android/provider/Contacts.html
    http://developer.android.com/resources/articles/contacts.html
  2. Read Contacts after sdk 2.0
    Refer to:


    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, 
       
    null, null, null, null);
     
    while (cursor.moveToNext()) {
       
    String contactId = cursor.getString(cursor.getColumnIndex(
         
    ContactsContract.Contacts._ID));
       
    String hasPhone = cursor.getString(cursor.getColumnIndex(
         
    ContactsContract.Contacts.HAS_PHONE_NUMBER));
       
    if (Boolean.parseBoolean(hasPhone)) {
                   
    // You know have the number so now query it like this
       
    Cursor phones = getContentResolver().query(
         
    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
         
    null,
         
    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,
         
    null, null);

    /*
    Or
    Cursor phones = getContentResolver().query(
         
    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
         
    null,
         
    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
         
    new String[]{
    contactId
    }, null);
    */
       
    while (phones.moveToNext()) {
  3.      String phoneNumber = phones.getString( 
           phones
    .getColumnIndex(
             
    ContactsContract.CommonDataKinds.Phone.NUMBER));                
       
    }
        phones
    .close();
       
    }
       
    Cursor emails = getContentResolver().query(
         
    ContactsContract.CommonDataKinds.Email.CONTENT_URI,
         
    null,
         
    ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,
         
    null, null);
       
    while (emails.moveToNext()) {
                   
    // This would allow you get several email addresses
       
    String emailAddress = emails.getString(
          emails
    .getColumnIndex(
           
    ContactsContract.CommonDataKinds.CommonDataColumns.DATA));
       
    }
       emails
    .close();
     
    }
      cursor
    .close();
  4. Read contacts from Android 1.6 and before
    refer to:
    2/

    package higherpass.TestContacts;

    import android.app.Activity;
    import android.content.ContentResolver;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.provider.Contacts;
    import android.provider.Contacts.People;

    public class TestContacts extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            ContentResolver cr = getContentResolver();
            Cursor cur = cr.query(People.CONTENT_URI,
                null, null, null, null);
            if (cur.getCount() > 0) {
             while (cur.moveToNext()) {
                 String id = cur.getString(cur.getColumnIndex(People._ID));
                 String name = cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
             }
            }
        }
    }


    if (Integer.parseInt(cur.getString(
                cur.getColumnIndex(People.PRIMARY_PHONE_ID))) > 0) {
            Cursor pCur = cr.query(
                    Contacts.Phones.CONTENT_URI,
                    null,
                    Contacts.Phones.PERSON_ID +" = ?",
                    new String[]{id}, null);
            int i=0;
            int pCount = pCur.getCount();
            String[] phoneNum = new String[pCount];
            String[] phoneType = new String[pCount];
            while (pCur.moveToNext()) {
                phoneNum[i] = pCur.getString(
                                   pCur.getColumnIndex(Contacts.Phones.NUMBER));
                phoneType[i] = pCur.getString(
                                   pCur.getColumnIndex(Contacts.Phones.TYPE));
                i++;
            }
        }
  5. xxx
阅读(1103) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~