最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android實現(xiàn)讀取、搜索聯(lián)系人的代碼

 更新時間:2015年03月16日 15:15:32   投稿:hebedich  
本文給大家分享的是在安卓系統(tǒng)中實現(xiàn)讀取搜索聯(lián)系人的代碼,非常的實用,想學(xué)習(xí)安卓開發(fā)的小伙伴一定不要錯過。

代碼很簡單,就不多廢話了

復(fù)制代碼 代碼如下:

//讀取聯(lián)系人
public static Uri CONTACTSURI = ContactsContract.Contacts.CONTENT_URI;//聯(lián)系人
    public static void getContactsInfo(Context context,String tag){
        String[] projections = new String[]{ContactsContract.Contacts._ID,ContactsContract.Contacts.DISPLAY_NAME};
        Cursor cursor = context.getContentResolver().query(CONTACTSURI, projections, null, null, null);
        int albumIndex = cursor.getColumnIndexOrThrow(projections[0]);
        int titleIndex = cursor.getColumnIndexOrThrow(projections[1]);
        Log.d(tag, cursor.getCount()+"");
        while(cursor.moveToNext()){
            String album = cursor.getString(albumIndex);
            String title = cursor.getString(titleIndex);
            Log.d(tag, album+":"+title);
        }
        cursor.close();
    }
    
    //根據(jù)聯(lián)系人搜索聯(lián)系人信息
    public static void searchContacts(Context context,String tag){
        String searchName = "Wang";
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, searchName);
        
    //  Uri uri2 = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, phoneNumber); 根據(jù)電話號碼查找聯(lián)系人
        
        String[] projection = new String[]{ContactsContract.Contacts._ID};
        Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
        String id = null;
        if (cursor.moveToFirst()) {
            id = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
        }
        cursor.close();
        if (id!=null) {
            String where = ContactsContract.Data._ID+"="+id;
            projection = new String[]{ContactsContract.Data.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER};
            Cursor searchcCursor = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, where, null, null);
            Log.d(tag, searchcCursor.getCount()+"");
            int nameIndex = searchcCursor.getColumnIndex(projection[0]);
            int numberIndex = searchcCursor.getColumnIndex(projection[1]);
            while(searchcCursor.moveToNext()){
                String name = searchcCursor.getString(nameIndex);
                String number = searchcCursor.getString(numberIndex);
                Log.d(tag, number+":"+name);
            }
            searchcCursor.close();
        }
    }

以上就是本文給大家分享的代碼的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評論

延津县| 忻城县| 府谷县| 沙洋县| 额尔古纳市| 大埔县| 河池市| 漳州市| 四平市| 琼结县| 高平市| 虹口区| 大竹县| 扎兰屯市| 武汉市| 仁怀市| 曲麻莱县| 永清县| 辽宁省| 汝城县| 博兴县| 石城县| 泸州市| 江北区| 沂源县| 大竹县| 钦州市| 新乡县| 萝北县| 通河县| 读书| 乐业县| 东安县| 绩溪县| 襄汾县| 嘉定区| 阿荣旗| 若羌县| 遂平县| 泰州市| 会理县|