得到联系人数据

/**
     * 查询所有联系人信息
     *   这里查询的是data表   
     *   
     */
    @SuppressLint("NewApi")
    private void findContack() {
        
          ContentResolver cr = this.getContentResolver();
          Cursor cur = cr.query(Data.CONTENT_URI, null, null, null, "raw_contact_id");
          
          int oldId = -1;
          while(cur.moveToNext()){
              int newId = cur.getInt(cur.getColumnIndex(Data.RAW_CONTACT_ID));
              //新的联系人   外键发生改变了
              if(oldId != newId ){
                  oldId = newId;
              }
              
              //取得当前记录的类型  
             String mimeType =  cur.getString(cur.getColumnIndex(Data.MIMETYPE));
             
             //取得名称相关
             if(StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)){
                 String familyName = cur.getString(cur.getColumnIndex(StructuredName.FAMILY_NAME));   //姓
                 String givenName =  cur.getString(cur.getColumnIndex(StructuredName.GIVEN_NAME));    //名
                 
                 mContactsName.add(givenName);
//               //绘制联系人名称
//                 title.setText(mContactsName.get(position));
//                 //绘制联系人号码
//                 text.setText(mContactsNumber.get(position));
//                 //绘制联系人头像
//                 iamge.setImageBitmap(mContactsPhonto.get(position));
                 Bitmap contactPhoto = null;
                 Long contactid =  cur.getLong(cur.getColumnIndex(StructuredName.CONTACT_ID));
                 Long photoid =  cur.getLong(cur.getColumnIndex(StructuredName.PHOTO_ID));
                 if(photoid > 0 ) {
                     Uri uri =ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,contactid);
                     InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
                     contactPhoto = BitmapFactory.decodeStream(input);
                 }else {
                     contactPhoto = BitmapFactory.decodeResource(getResources(), R.drawable.contact_photo);
                 }
                 
                 mContactsPhonto.add(contactPhoto);
             }
             
             //取得电话相关
             else if(Phone.CONTENT_ITEM_TYPE.equals(mimeType)){
                 
                 int phoneType = cur.getInt(cur.getColumnIndex(Phone.TYPE));
                 //宅电信息     家庭电话
                 if(phoneType == Phone.TYPE_HOME){
//                     p.homeTel = cur.getString(cur.getColumnIndex(Phone.NUMBER));
                 }
                 
                 //手机信息
                 else if(phoneType == Phone.TYPE_MOBILE){
                     String mobileTel = cur.getString(cur.getColumnIndex(Phone.NUMBER));
                     mContactsNumber.add(mobileTel);
                 }
             }
             
             //取得及时(im)信息   msn  qq
             else if(Im.CONTENT_ITEM_TYPE.equals(mimeType)){
                 
                  int imType = cur.getInt(cur.getColumnIndex(Im.PROTOCOL));
                  
                 //msn
                 if(imType == Im.PROTOCOL_MSN){
//                     p.msn = cur.getString(cur.getColumnIndex(Im.DATA));
                 }
                 
                 //QQ
                 else if(imType == Im.PROTOCOL_QQ){
                     String qq = cur.getString(cur.getColumnIndex(Im.DATA));
                     Log.i("DD","===qq===="+qq);
                 }
             }
          }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中实现微信联系人索引条可以使用以下步骤: 1. 创建一个名为`IndexBar`的组件,用于展示索引条。该组件可以包含一个包含索引项的列表。 2. 在父组件中,获取联系人列表数据。 3. 对联系人列表进行处理,提取首字母并去重,得到一个包含所有首字母的索引数组。 4. 在`IndexBar`组件中,使用`v-for`指令遍历索引数组,生成索引项。 5. 给每个索引项添加点击事件,点击时触发一个自定义事件,并传递对应的首字母作为参数。 6. 在父组件中监听`IndexBar`组件触发的自定义事件,并根据传递的首字母进行相应操作,如滚动到对应的联系人分组。 以下是一个示例代码: ```vue <template> <div> <IndexBar @clickIndex="scrollToGroup" /> <div v-for="(group, index) in contactGroups" :key="index"> <h2>{{ group }}</h2> <ul> <li v-for="contact in contacts" :key="contact.id"> {{ contact.name }} </li> </ul> </div> </div> </template> <script> import IndexBar from './IndexBar.vue'; export default { components: { IndexBar, }, data() { return { contacts: [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }, { id: 3, name: 'Charlie' }, // ... ], }; }, computed: { contactGroups() { const groups = []; this.contacts.forEach((contact) => { const firstLetter = contact.name.charAt(0).toUpperCase(); if (!groups.includes(firstLetter)) { groups.push(firstLetter); } }); return groups; }, }, methods: { scrollToGroup(letter) { // 根据传递的首字母进行滚动操作 // ... }, }, }; </script> ``` 这只是一个简单示例,你可以根据实际需求进行相应的样式和逻辑调整。希望能帮到你!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值