Windows Phone 8 新增功能:支援第三方應用建立自訂連絡人Custom Contact Store。

來源:互聯網
上載者:User

Windows Phone 8 將允許開發人員建立自己的Custom Contact Store。應用程式通過應用程式添加新連絡人後,先連絡人出現在Windows Phone hub中,並和使用者的系統連絡人並存。開發人員可以為建立連絡人的的標準屬性,如電話號碼、名稱等,也可以儲存自訂屬性。開發人員還可以利用連絡人儲存api來同步他們的使用者的連絡人清單到雲端。

建立連絡人:

        private async void Button_Click_4(object sender, RoutedEventArgs e)        {            //var store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadOnly,            //    ContactStoreApplicationAccessMode.LimitedReadOnly);            //連結並開啟連絡人, 需要添加<Capability Name="ID_CAP_CONTACTS" /> 能力            var store = await ContactStore.CreateOrOpenAsync();            Debug.WriteLine("RevisionNumber:" + store.RevisionNumber);            StoredContact sc = new StoredContact(store);            sc.DisplayName = "Mark";            sc.HonorificPrefix = "et";            await sc.SaveAsync();        }

讀取連絡人

        private async void Button_Click_2(object sender, RoutedEventArgs e)        {            //var store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadOnly,            //    ContactStoreApplicationAccessMode.LimitedReadOnly);                         //連結並開啟連絡人, 需要添加<Capability Name="ID_CAP_CONTACTS" /> 能力            var store = await ContactStore.CreateOrOpenAsync();            Debug.WriteLine("RevisionNumber:" + store.RevisionNumber);            //建立連絡人查詢            ContactQueryResult result = store.CreateContactQuery();            var count = await result.GetContactCountAsync();            Debug.WriteLine("GetContactCountAsync:" + count);            ContactQueryOptions option = result.GetCurrentQueryOptions();            foreach (string filed in option.DesiredFields)            {                Debug.WriteLine("filed:" + filed);            }                        //擷取連絡人清單            var contacts = await result.GetContactsAsync();            foreach (StoredContact contact in contacts)            {                Debug.WriteLine("DisplayName:" + contact.DisplayName);                //將連絡人資料轉換成VCard檔案                var vCard = await contact.ToVcardAsync();                IInputStream inputStream = vCard.GetInputStreamAt(0);                ulong length = vCard.Size;                try                {                    //將vCard檔案流使用字串輸出                    var readBuf = new Windows.Storage.Streams.Buffer((uint)length);                    var vCardOp = vCard.GetInputStreamAt(0).ReadAsync(readBuf, (uint)length, InputStreamOptions.Partial);                    vCardOp.Completed = (IAsyncOperationWithProgress<IBuffer, uint> asyncAction, AsyncStatus asyncStatus) =>                    {                        switch (asyncStatus)                        {                            case AsyncStatus.Completed:                                Debug.WriteLine("vCardString:" + MainPage.BufferToString(readBuf));                                break;                            case AsyncStatus.Error:                                break;                            case AsyncStatus.Canceled:                                // Read is not cancelled in this sample.                                break;                        }                    };                }                catch (Exception exp)                {                    Debug.WriteLine(exp.ToString());                }            }        }

相關文章

聯繫我們

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