首页 > 安全资讯 >

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

13-08-24

public String getPeople(String mNumber) {String name = ""; String[] projection = { ContactsContract.PhoneLookup.DISPLAY_NAME, /*ContactsContract.CommonDataKinds.Phone.NUMBER*/}; Curs...

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;
}  
相关文章
最新文章
热点推荐