读取联系人信息

来源:互联网 发布:新网域名转入阿里云 编辑:程序博客网 时间:2024/05/01 06:13
读取联系人信息,用了android自带的PEOPLE.CONTENT_URI,provider.Contacts.CONTENT_URI都不好用,获取不到联系人号码,随后找到Phones.CONTENT_URI才顺利显示。
ContentResolver contentResolver = this.getContentResolver();

       Cursor cursor = contentResolver.query(Phones.CONTENT_URI, null,null,
           null, null);

       Log.e("ray", "" + cursor.getCount());

       if (cursor.moveToFirst())
       {

           long start = System.currentTimeMillis();

           do
           {

               int nameIndex = cursor.getColumnIndex(Phones.DISPLAY_NAME);

               int numberIndex = cursor.getColumnIndex(Phones.NUMBER);

               String contactName = cursor.getString(nameIndex);

               String contactNumber = cursor.getString(numberIndex);

               Log.e("ray", "contactName" + contactName + "contactNumber"
                   + contactNumber);

           }
           while (cursor.moveToNext());

           long end = System.currentTimeMillis();

           Log.e("ray", "time  " + (end - start));
       }
       cursor.close();
0 0
原创粉丝点击