如何从手机号码 [英] how to get mobile number from contact

查看:190
本文介绍了如何从手机号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要回升,从联系人列表中的联系人,然后得到只有姓名和手机号码,从选中的联系人将它们存储在应用程序中,我顺利拿到了名字,但我怎么能验证联系人有一个移动号码(而不是家庭),然后拿到多少?

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 get the name, BUT how can I verify that the contact has a mobile number (not a home) then get the number?

和我怎么能检查,如果接触有一个或多个手机号码?

And how can I check if the contact has one or more mobile numbers?

推荐答案

在Android的联系人姓名和电话号码是保存在不同的ContentProvider所以采取CONTACT_ID从下面code

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();
      }

和比这个ID就可以得到手机号码等详细信息

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<no.length;i++){
        if(no[i].trim().toString().equalsIgnoreCase("")){
            break;
        }
        int id=Integer.parseInt(no[i]);
        //Cursor cur=cr.query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts._ID +" = "+id, null, null);
        //cur.moveToFirst();

        Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"="+id, null, null);
        pCur.moveToFirst();

        while(pCur.isAfterLast()==false){
                 if(Integer.parseInt(pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)))==(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)){
    //               String uname=cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).toString();
                     String tempMoNo=pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                     Log.e("Activity result selelength is",String.valueOf(seleContact.length()));
                     String[] temp=tempMoNo.split("-");
                     String MoNo="";
                     int le=temp.length;
                     for(int j=0;j<le;j++){
                         MoNo +=temp[j];
                     }

                     if (seleContact.length() > 0) {
                            seleContact += "," + (MoNo);
                        } else {
                            seleContact += (MoNo);
                            }            
                 }
            pCur.moveToNext();
             }
        pCur.close();
    }

    return seleContact;
}

这篇关于如何从手机号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆