android 获取手机联系人信息

public static final String[] PHONES_PROJECTION = new String[]
    {
        Phone.DISPLAY_NAME,
        Phone.NUMBER,
        Photo.PHOTO_ID,
        Phone.CONTACT_ID
    };


   public static final int PHONES_DISPLAY_NAME_INDEX = 0;
    public static final int PHONES_NUMBER_INDEX = 1;
    public static final int PHONES_PHOTO_ID_INDEX = 2;
    public static final int PHONES_CONTACT_ID_INDEX = 3;


/**

                 * 获取联系人信息
                 */
                ContentResolver resolver = this.getContentResolver();
                /**
                 *  获取手机联系人
                 */
                Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,Parameters.PHONES_PROJECTION, null, null, null);
                
                if (null != phoneCursor)
                {
                    while (phoneCursor.moveToNext())
                    {
                        String phoneNumber = phoneCursor.getString(Parameters.PHONES_NUMBER_INDEX);// 得到手机号码
                        if (TextUtils.isEmpty(phoneNumber)) continue;// 当手机号码为空的或者为空字段 跳过当前循环
                        String contactName = phoneCursor.getString(Parameters.PHONES_DISPLAY_NAME_INDEX);// 得到联系人名称
                        String c_temp;
                        if (text_person.length() > contactName.length())
                        {
                            c_temp = PinyinUtil.hanziToPinyin(contactName,"").substring(0, contactName.length());
                        }
                        else
                        {
                            c_temp = PinyinUtil.hanziToPinyin(contactName,"").substring(0, text_person.length());
                        }
                        if (contactName.contains(text_person) ||
                            c_temp.contains(text_person))
                        {
                             diffrent = 1;
                             Contact contact = new Contact();
                             contact.setName(contactName);
                             contact.setNumber(phoneNumber);
                             list.add(contact);
                             break;
                        }
                    }
                    phoneCursor.close();

                }


<!-- 读取联系人权限-->   
<uses-permissionandroid:name="android.permission.READ_CONTACTS"/>  
<!-- 拨打电话权限-->  
<uses-permissionandroid:name="android.permission.CALL_PHONE"/>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值