locked
Contact Picker not bringing through thumbnail

    Question

  • Hey,

    I'm currently writing a app where I want keep a list contacts that the user selects using the contact picker from the phones contacts.

    I am following the Contact Picker sample to do this (Single item) and for the most part it is working well.  I have my emulator connected to my microsoft account bringing through all my contacts into the people hub.

    When I come to getting the thumbnail from the stream into my bitmapimage the thumbnail property is always null on the Contact object even though there is a thumbnail when I view it in the people hub.  I dont understand why?

    This part below is what i'm talking about

    //contact.Thumbnail is always null

    if (contact.Thumbnail != null)                  {                      IRandomAccessStreamWithContentType stream = await contact.Thumbnail.OpenReadAsync();                      if (stream != null && stream.Size > 0)                      {                          BitmapImage bitmap = new BitmapImage();                          bitmap.SetSource(stream);                          OutputThumbnail.Source = bitmap;                      }                      else                      {                          OutputThumbnail.Source = null;                      }                  }




    cheers


    GrayFox Where not just tools of the government!

    Wednesday, October 22, 2014 10:13 PM

Answers

  • I've reported this issue. And get the following code can work around this issue for now:

    Please go to ContactItemAdapter.cs and change the GetThumbnail method to following:

     private async void GetThumbnail(Contact contact)
            {
    #if WINDOWS_PHONE_APP
                var contactStore = await ContactManager.RequestStoreAsync();
                Contact contact2 = await contactStore.GetContactAsync(contact.Id);
                if (contact2.Thumbnail != null)
                {
                    IRandomAccessStreamWithContentType stream = await contact2.Thumbnail.OpenReadAsync();
                    if (stream != null && stream.Size > 0)
                    {
                        this.Thumbnail = new BitmapImage();
                        this.Thumbnail.SetSource(stream);
                    }
                }
    #else
                if (contact.Thumbnail != null)
                {
                    IRandomAccessStreamWithContentType stream = await contact.Thumbnail.OpenReadAsync();
                    if (stream != null && stream.Size > 0)
                    {
                        this.Thumbnail = new BitmapImage();
                        this.Thumbnail.SetSource(stream);
                    }
                }
    #endif
    
            }


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 24, 2014 6:09 AM

All replies

  • Hi,

    Thanks for reporting this.

    We've reproduced this and I am confirming this with our product team.

    I will let you know once I get any update.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, October 23, 2014 7:20 AM
  • I've reported this issue. And get the following code can work around this issue for now:

    Please go to ContactItemAdapter.cs and change the GetThumbnail method to following:

     private async void GetThumbnail(Contact contact)
            {
    #if WINDOWS_PHONE_APP
                var contactStore = await ContactManager.RequestStoreAsync();
                Contact contact2 = await contactStore.GetContactAsync(contact.Id);
                if (contact2.Thumbnail != null)
                {
                    IRandomAccessStreamWithContentType stream = await contact2.Thumbnail.OpenReadAsync();
                    if (stream != null && stream.Size > 0)
                    {
                        this.Thumbnail = new BitmapImage();
                        this.Thumbnail.SetSource(stream);
                    }
                }
    #else
                if (contact.Thumbnail != null)
                {
                    IRandomAccessStreamWithContentType stream = await contact.Thumbnail.OpenReadAsync();
                    if (stream != null && stream.Size > 0)
                    {
                        this.Thumbnail = new BitmapImage();
                        this.Thumbnail.SetSource(stream);
                    }
                }
    #endif
    
            }


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, October 24, 2014 6:09 AM
  • Thanks that works.

    GrayFox Where not just tools of the government!

    Friday, October 24, 2014 7:00 AM
  • Thanks Alan! That works great!

    Just remember to add the ID_CAP_CONTACTS flag to the manifest to allow access to the ContactManager.

    Tuesday, November 04, 2014 4:01 AM