how to get mobile number from contact

前端 未结 1 1335
一生所求
一生所求 2021-01-24 00:39

My application require to pick a contact from contacts list, then get ONLY the name and mobile number from the chosen contact to store them in the application, I successfully ge

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-24 01:11

    In android Contact name and number is save in different ContentProvider so for take contact_id from below code

      cur=cr.query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.HAS_PHONE_NUMBER +" > 0", null, null);
          cur.moveToFirst();
          while(cur.isAfterLast()==false){
            //    Log.e("Name is:",cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
                  Fid=Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)));
    
                  int id=Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)));
                  Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null, null, null);
    
                  pCur.moveToFirst();
                  while (pCur.isAfterLast()==false) {
                      int idinner=Integer.parseInt(pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)));
                      if(idinner==id){ 
    
    //Add id to Array
    
                     }
                     pCur.moveToNext();
                }
              cur.moveToNext();
          }
    

    and than this id you can get mobile number and other details

    public String getNo(String[] no){
    
        String seleContact="";  
    //  String[] contactNos=new String[no.length];
        for(int i=0;i 0) {
                                seleContact += "," + (MoNo);
                            } else {
                                seleContact += (MoNo);
                                }            
                     }
                pCur.moveToNext();
                 }
            pCur.close();
        }
    
        return seleContact;
    }
    

    0 讨论(0)
提交回复
热议问题