question

Prak-4084 avatar image
0 Votes"
Prak-4084 asked ·

Xamarin Essentials getting Full contacts

I am using Xamarin Essentials (1.6.0) in my project. I am able get contacts from Android and Iphone but it is only giving me Displayname, Phonenumbers and Emails. Is there any way I can get full address stored in contacts as well?

Any help appreciated.

dotnet-xamarinessentials
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered ·

Hello,


Welcome to our Microsoft Q&A platform!

Please try to update your Xamarin.Essentials nuget to the latest version (1.6.1), then when we use the following code,we can get the full contact .

 try
 {
     var contact = await Contacts.PickContactAsync();
    
     if(contact == null)
         return;
    
     var id = contact.Id;
     var namePrefix = contact.NamePrefix;
     var givenName = contact.GivenName;
     var middleName = contact.MiddleName;
     var familyName = contact.FamilyName;
     var nameSuffix = contact.NameSuffix;
     var displayName = contact.DisplayName;
     var phones = contact.Phones; // List of phone numbers
     var emails = contact.Emails; // List of email addresses
 }
 catch (Exception ex)
 {
     // Handle exception here.
 }

And when we click into the source code of Contact of Xamarin.Essentials, we will find that nuget Xamarin.Essentials has expose the following fields for us:

61704-image.png

For more details, you can check: https://docs.microsoft.com/en-us/xamarin/essentials/contacts?tabs=android


Best Regards,

Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.


Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.






image.png (54.6 KiB)
· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JessieZhang-2116 , I tried to select a single contact using an Android emulator. As soon as I selected a contact, my app went into the background. When I tried to retrieve the app, it started from its first page.
Also, on pressing the back button in the system Contacts app (both, hardware back and navigation bar back button), the app crashes!
It gives the following exception : " system.threading.tasks.taskcanceledexception a task was canceled at xamarin.essentials.platformpickcontactasync "

What can I do in this case?

Please find my question link for the same : app-crashing-when-selecting-contact-and-trying-to.html


0 Votes 0 ·