讀取手機本地全部連絡人

來源:互聯網
上載者:User

標籤:

    /**     * 讀取 連絡人     * @param context     * @return     */    public static List<Map<String, String>> getLocalContacts(Context context) {                List<Map<String, String>> datas = new ArrayList<Map<String,String>>();                ContentResolver cr = context.getContentResolver();                Uri uriRawContacts = Uri.parse("content://com.android.contacts/raw_contacts");                Uri uriData = Uri.parse("content://com.android.contacts/data");                Cursor rawContactsCursor = cr.query(uriRawContacts,                 new String[] { "contact_id"},                 null,                 null,                 null);                String data1 = null;                String mimetype = null;                while(rawContactsCursor.moveToNext()){            String contactId = rawContactsCursor.getString(rawContactsCursor.getColumnIndex("contact_id"));                        if(contactId != null){                                Map<String, String> data = new HashMap<String,String>();                                Cursor dataCursor = cr.query(uriData,                         new String[]{"data1","mimetype"},                         "contact_id=?",                         new String[]{contactId},                         null);                                while(dataCursor.moveToNext()){                                        data1 = dataCursor.getString(dataCursor.getColumnIndex("data1"));                    mimetype = dataCursor.getString(dataCursor.getColumnIndex("mimetype"));                                        if("vnd.android.cursor.item/name".equals(mimetype)){                        data.put("name", data1);                        //Log.i(StaticDatas.CONTACTSHELPERUTIL_LOG_TAG, "name is " + data1);                    }else if("vnd.android.cursor.item/phone_v2".equals(mimetype)){                        data.put("phone", data1);                        //Log.i(StaticDatas.CONTACTSHELPERUTIL_LOG_TAG, "phone is " + data1);                    }                }                                datas.add(data);                                dataCursor.close();            }        }                rawContactsCursor.close();                return datas;    }

 

讀取手機本地全部連絡人

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.