Android联系人数据库全

/**
     * case 1 only nickname  input
     * @param nicknam
     * @deprecated
     */
    public void selectBynickname2(String nickname, TableLayout layout) {
       
          //select contract nickname
        String selectionNick = Nickname.NAME +" = ?";  
        String[] selectionArgsNick = new String[]{nickname};
       
        ContentResolver cr = getContentResolver();
        Cursor contractscursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, selectionNick, selectionArgsNick, null);
       
      
        while(contractscursor.moveToNext()) {
           
            int NICKNAME = contractscursor.getColumnIndex(Nickname.NAME);
            int ID = contractscursor.getColumnIndex(ContactsContract.Contacts._ID);
            int PHOTO = contractscursor.getColumnIndex(ContactsContract.Data.DATA15);
            //int presence = (int)contractscursor.getLong(PRESENCE_STATUS);
            String nicknametemp = (String)contractscursor.getString(NICKNAME);
            String idtemp = (String)contractscursor.getString(ID);
            byte[] phototemp = contractscursor.getBlob(PHOTO);
            Bitmap photobmp = null;
             
             if(Util.isEmpty(phototemp)) {
                 //default photo
                photobmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
               
             } else {
                photobmp = BitmapFactory.decodeByteArray(phototemp, 0, phototemp.length);
             }
           
           
            //select email
            String selectionEmail = Email.CONTACT_ID + " = ?";  
            String[] selectionArgsEmail = new String[]{idtemp};
            Cursor emailcursor = cr.query(Email.CONTENT_URI,
                    null, selectionEmail, selectionArgsEmail, null);
           
          
            while(emailcursor.moveToNext()) {
               
                int EMAIL = emailcursor.getColumnIndex(Email.DATA);
               
                String email = (String)emailcursor.getString(EMAIL);
               
                layout.addView(row(new Contract(nickname, email,photobmp)));
               
            }
           
               
        }
    }
   
    /**
     * case 1 only email  input
     * @param nicknam
     * @deprecated
     */
    public void selectByemail2(String email, TableLayout layout) {
       
            ContentResolver cr = getContentResolver();
           
            //select email
            String selectionEmail = Email.DATA +" = ?";  
            String[] selectionArgsEmail = new String[]{email};
            Cursor emailcursor = cr.query(Email.CONTENT_URI,
                    null, selectionEmail, selectionArgsEmail, null);
           
          
            while(emailcursor.moveToNext()) {
               
                int EMAIL = emailcursor.getColumnIndex(Email.DATA);
                int ID = emailcursor.getColumnIndex(Email.CONTACT_ID);
                String emailtemp = (String)emailcursor.getString(EMAIL);
                String idtemp = (String)emailcursor.getString(ID);
               
                //select contract nickname
                String selectionNick = ContactsContract.Contacts._ID +" = ?";  
                String[] selectionArgsNick = new String[]{idtemp};
               
                Cursor contractscursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
                        null, selectionNick, selectionArgsNick, null);
               
              
                while(contractscursor.moveToNext()) {
                     int NICKNAME = contractscursor.getColumnIndex(Nickname.NAME);
                     int PHOTO = contractscursor.getColumnIndex(ContactsContract.Data.DATA15);
                     
                      String nicknametemp = (String)contractscursor.getString(NICKNAME);
                      byte[] phototemp = contractscursor.getBlob(PHOTO);
                      Bitmap photobmp = null;
                      
                      if(Util.isEmpty(phototemp)) {
                         photobmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
                        
                      } else {
                         photobmp = BitmapFactory.decodeByteArray(phototemp, 0, phototemp.length);
                      }
                      
                     layout.addView(row(new Contract(nicknametemp, emailtemp, photobmp)));
                
                }
               
            }
           
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值