none
WP8.1RT中,如何修改人脉中的联系人, RRS feed

  • 问题

  • 我搜了很多信息都没找到,我是想通过程序修改人脉中联系人的头像,不知sdk中是否提供相关接口?
    2015年1月10日 8:21

答案

  • 你好,

    我们可以使用StoredContact.SetDisplayPictureAsync方法去设置联系人头像,以下是我的代码示例:

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
                ContactStore contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);
    
                ContactInformation contactInformation = new ContactInformation();
                var properties = await contactInformation.GetPropertiesAsync();
                properties.Add(KnownContactProperties.FamilyName, "test");
                properties.Add(KnownContactProperties.Telephone, "12345678");
                StoredContact storeContact = new StoredContact(contactStore, contactInformation);
    
                StorageFile imagefile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Build.png", UriKind.RelativeOrAbsolute));
                Stream stream = await imagefile.OpenStreamForReadAsync();
                IInputStream inputStream = stream.AsInputStream();
                await storeContact.SetDisplayPictureAsync(inputStream);
                await storeContact.SaveAsync();
    
                //Get Current Contact Avatar
                IRandomAccessStream raStream = await storeContact.GetDisplayPictureAsync();
    
                BitmapImage bi = new BitmapImage();
                bi.SetSource(raStream);
                img.Source = bi;
    }

    截图:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年1月12日 10:01
    版主
  • 多谢您的回答,

    我在网上也找到诸如您提供的代码,奇怪的是,我这里的ContactStore并没有CreateOrOpenAsync方法:

    我用的是WP8.1RT框架,

    你好,

    注意引用的是 Windows.Phone.PersonalInformation

    using Windows.Phone.PersonalInformation;

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 jesse hao 2015年1月13日 8:25
    2015年1月13日 4:56
    版主

全部回复

  • 你好,

    我们可以使用StoredContact.SetDisplayPictureAsync方法去设置联系人头像,以下是我的代码示例:

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
                ContactStore contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);
    
                ContactInformation contactInformation = new ContactInformation();
                var properties = await contactInformation.GetPropertiesAsync();
                properties.Add(KnownContactProperties.FamilyName, "test");
                properties.Add(KnownContactProperties.Telephone, "12345678");
                StoredContact storeContact = new StoredContact(contactStore, contactInformation);
    
                StorageFile imagefile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Build.png", UriKind.RelativeOrAbsolute));
                Stream stream = await imagefile.OpenStreamForReadAsync();
                IInputStream inputStream = stream.AsInputStream();
                await storeContact.SetDisplayPictureAsync(inputStream);
                await storeContact.SaveAsync();
    
                //Get Current Contact Avatar
                IRandomAccessStream raStream = await storeContact.GetDisplayPictureAsync();
    
                BitmapImage bi = new BitmapImage();
                bi.SetSource(raStream);
                img.Source = bi;
    }

    截图:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年1月12日 10:01
    版主
  • 多谢您的回答,

    我在网上也找到诸如您提供的代码,奇怪的是,我这里的ContactStore并没有CreateOrOpenAsync方法:

    我用的是WP8.1RT框架,

    2015年1月12日 14:44
  • 多谢您的回答,

    我在网上也找到诸如您提供的代码,奇怪的是,我这里的ContactStore并没有CreateOrOpenAsync方法:

    我用的是WP8.1RT框架,

    你好,

    注意引用的是 Windows.Phone.PersonalInformation

    using Windows.Phone.PersonalInformation;

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 jesse hao 2015年1月13日 8:25
    2015年1月13日 4:56
    版主