a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 系統 > Android > 正文

android實現讀取、搜索聯系人的代碼

2020-04-11 11:39:04
字體:
來源:轉載
供稿:網友

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

復制代碼 代碼如下:

//讀取聯系人
public static Uri CONTACTSURI = ContactsContract.Contacts.CONTENT_URI;//聯系人
    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();
    }
    
    //根據聯系人搜索聯系人信息
    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); 根據電話號碼查找聯系人
        
        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();
        }
    }

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产福利视频 | 91高清免费看 | 福利在线看| 黄色网址免费在线 | 国产成人jvid在线播放 | 狠久久 | 日韩国产一区二区 | 久久99精品久久久久久琪琪 | www.久久.com| 91在线 | 亚洲 | 午夜在线电影 | 欧美久热| 国产成人福利在线观看 | 亚洲欧美日韩另类精品一区二区三区 | 91视频免费观看 | 精品视频一区二区三区 | 日韩三级av| 狠狠爱天天干 | 视频一区 中文字幕 | 久久亚洲高清 | 成人精品视频在线观看 | 色婷婷综合在线视频 | 日韩在线视频免费看 | 国产免费一区 | 久草久草久草 | 国产精品久久久久久久久久久杏吧 | 欧美综合久久 | 国产精品一区二区在线观看 | 青草在线视频 | 日韩av高清在线观看 | 污网站在线浏览 | 97男人的天堂 | 91成人在线 | 综合久久综合久久 | 久久精品极品 | 国产欧美日韩一区二区三区 | 久久久精选 | 天堂久久一区 | 日韩在线一区二区三区 | www久久综合 | 国产干干干 |