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

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

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

代碼很簡(jiǎn)單,就不多廢話了

復(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ù)電話號(hào)碼查找聯(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();
        }
    }

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

相關(guān)文章

最新評(píng)論

漠河县| 来宾市| 台安县| 玉溪市| 黎川县| 吴忠市| 沾化县| 水城县| 宁陵县| 油尖旺区| 修水县| 普陀区| 盈江县| 黄大仙区| 武穴市| 沁源县| 叶城县| 云龙县| 威海市| 台州市| 凤凰县| 安远县| 丰顺县| 德化县| 仁寿县| 特克斯县| 台湾省| 长春市| 东至县| 昌黎县| 恩施市| 郑州市| 定远县| 紫云| 萨迦县| 吉隆县| 呈贡县| 潍坊市| 阳高县| 南乐县| 松江区|