android 寫入連絡人

來源:互聯網
上載者:User

標籤:android   ext   get   資料   類   cti   

  1. public void testInsert() { 
  2.         ContentValues values = new ContentValues(); 
  3. /*
  4.          * 首先向RawContacts.CONTENT_URI執行一個空值插入,目的是獲得系統返回的rawContactId
  5.          */
  6.         Uri rawContactUri = this.getContext().getContentResolver().insert(RawContacts.CONTENT_URI, values); 
  7. long rawContactId = ContentUris.parseId(rawContactUri); 
  8. //往data表裡寫入姓名資料
  9.         values.clear(); 
  10.         values.put(Data.RAW_CONTACT_ID, rawContactId); 
  11.         values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); //內容類型
  12.         values.put(StructuredName.GIVEN_NAME, "李天山"); 
  13. this.getContext().getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); 
  14. //往data表裡寫入電話資料
  15.         values.clear(); 
  16.         values.put(Data.RAW_CONTACT_ID, rawContactId); 
  17.         values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); 
  18.         values.put(Phone.NUMBER, "13921009789"); 
  19.         values.put(Phone.TYPE, Phone.TYPE_MOBILE); 
  20. this.getContext().getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); 
  21. //往data表裡寫入Email的資料
  22.         values.clear(); 
  23.         values.put(Data.RAW_CONTACT_ID, rawContactId); 
  24.         values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE); 
  25.         values.put(Email.DATA, "[email protected]"); 
  26.         values.put(Email.TYPE, Email.TYPE_WORK); 
  27. this.getContext().getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values); 
  28.     } 

聯繫我們

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