当前位置:操作系统 > 安卓/Android >>

根据指定电话号码得到通讯录上的姓名

public String getPeople(String mNumber) {
String name = "";
        String[] projection = { ContactsContract.PhoneLookup.DISPLAY_NAME, 
                                /*ContactsContract.CommonDataKinds.Phone.NUMBER*/}; 
   
    Cursor cursor = this.getContentResolver().query( 
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                projection,     
            ContactsContract.CommonDataKinds.Phone.NUMBER + " = '" + mNumber + "'", 
                null,          
                null);  
        if( cursor == null ) { 
            return ""; 
    } 
        for( int i = 0; i < cursor.getCount(); i++ ) 
        { 
        cursor.moveToPosition(i); 
           
            int nameFieldColumnIndex = cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME); 
cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);   
            name = cursor.getString(nameFieldColumnIndex); 
            Log.i(TAG, "lanjianlong" + name + " .... " + nameFieldColumnIndex); // 这里提示 force close 
         break;
        } 
        if(cursor != null){
        cursor.close();
        }
        return name;
}  
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,