通过号码获得联系人(识别飞信号与+86等号码问题)

/** 
     * 通过电话号码获取姓名 
     */  
    public String getContactNameFromPhoneNum(Context context, String phoneNum)  
    {  
        String contactName = "";  
          
        //处理电话号码格式问题  
        if (phoneNum.length()>11)  
        {  
            ContentResolver cr = context.getContentResolver();  
            Cursor pCur = cr.query(  
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,  
                    ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?",  
                    new String[]  
                    { phoneNum }, null);  
            if (pCur.moveToFirst())  
            {  
                contactName = pCur  
                        .getString(pCur  
                                .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));  
                pCur.close();  
            }  
            if (contactName.equals(""))  
            {  
                phoneNum=phoneNum.substring(phoneNum.length()-11);  
                System.out.println(phoneNum);  
            }         
        }         
          
        ContentResolver cr = context.getContentResolver();  
        Cursor pCur = cr.query(  
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,  
                ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?",  
                new String[]  
                { phoneNum }, null);  
        if (pCur.moveToFirst())  
        {  
            contactName = pCur  
                    .getString(pCur  
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));  
            pCur.close();  
        }  
        return contactName;  
    }

你可能感兴趣的:(通过号码获得联系人(识别飞信号与+86等号码问题))