Android-通訊錄:新增連絡人...

來源:互聯網
上載者:User

標籤:通訊錄

//新增連絡人...,使用事務    public void testAddContact()  {        String name[]={"周杰倫","謝霆鋒","言承旭","林俊傑","潘瑋柏","明道"," 甄子丹"," 周渝民",    "羅志祥", "五月天","劉德華"," 麥浚龍"," 成龍"," 蘇有朋"," 郭品超"," 阿杜"    ,"鄭嘉穎"," 吳尊"," 炎亞綸"," 王紹偉"," 唐禹哲"," 巫迪文"," 汪東城" };    for(String ss:name)    {    //首先插入空值,再得到rawContactsId ,用於下面插值               ContentValues values = new ContentValues ();               //insert a null value              Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI,values);               long rawContactsId = ContentUris.parseId(rawContactUri);                         //往剛才的空記錄中插入姓名               values.clear();               //A reference to the _ID that this data belongs to              values.put(StructuredName.RAW_CONTACT_ID,rawContactsId);               //"CONTENT_ITEM_TYPE" MIME type used when storing this in data table              values.put(Data.MIMETYPE,StructuredName.CONTENT_ITEM_TYPE);               //The name that should be used to display the contact.              values.put(StructuredName.DISPLAY_NAME,ss);               //insert the real values              getContentResolver().insert(Data.CONTENT_URI,values);               //插入電話               values.clear();               values.put(Phone.RAW_CONTACT_ID,rawContactsId);               //String "Data.MIMETYPE":The MIME type of the item represented by this row              //String "CONTENT_ITEM_TYPE": MIME type used when storing this in data table.              values.put(Data.MIMETYPE,Phone.CONTENT_ITEM_TYPE);               values.put(Phone.NUMBER,"1008611");               getContentResolver().insert(Data.CONTENT_URI,values);       }        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.