Windows Phone 8: supports creating custom contact store for third-party applications.

Source: Internet
Author: User
Tags vcard
 


Windows Phone 8 allows developers to create their own m contact store. After the application adds a new contact through the application, the contact appears in Windows Phone hub and coexist with the user's system contact. Developers can create standard attributes for contacts, such as phone numbers and names, or store custom attributes. Developers can also use the contact storage API to synchronize the contact list of their users to the cloud.


Create a contact:


private async void Button_Click_4 (object sender, RoutedEventArgs e)
         {
             // var store = await ContactStore.CreateOrOpenAsync (ContactStoreSystemAccessMode.ReadOnly,
             // ContactStoreApplicationAccessMode.LimitedReadOnly);


             // link and open the contact, you need to add <Capability Name = "ID_CAP_CONTACTS" /> ability
             var store = await ContactStore.CreateOrOpenAsync ();
             Debug.WriteLine ("RevisionNumber:" + store.RevisionNumber);

             StoredContact sc = new StoredContact (store);
             sc.DisplayName = "Mark";
             sc.HonorificPrefix = "et";
             await sc.SaveAsync ();
         }

Read contacts


private async void Button_Click_2 (object sender, RoutedEventArgs e)
        {

            // var store = await ContactStore.CreateOrOpenAsync (ContactStoreSystemAccessMode.ReadOnly,
            // ContactStoreApplicationAccessMode.LimitedReadOnly);
            
 
            // link and open the contact, you need to add <Capability Name = "ID_CAP_CONTACTS" /> ability
            var store = await ContactStore.CreateOrOpenAsync ();
            Debug.WriteLine ("RevisionNumber:" + store.RevisionNumber);

            // Create contact query
            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);
            }
            

            // Get contact list
            var contacts = await result.GetContactsAsync ();
            foreach (StoredContact contact in contacts)
            {
                Debug.WriteLine ("DisplayName:" + contact.DisplayName);
                // Convert contact data into a VCard file
                var vCard = await contact.ToVcardAsync ();
                IInputStream inputStream = vCard.GetInputStreamAt (0);
                ulong length = vCard.Size;

                try
                {
                    // Output the vCard file stream as a string
                    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 ());
                }

            }
        } 



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.