Sometimes we have to integrate some functionalities into our Apps that require obtaining information from contacts, previously, to achieve this we had to take more development time, but now we have very good news!!! Xamarin Essentials included it for us!💚 We can implement this simply and easily! In this post, we will be learning how to do it! 😎
First of all… What do I need?
Let’s add some platform settings. To implement it, follow the instructions added below:
We have more than one way to do it, let’s see:
Right click in your Android project ➖ Options ➖Android Application ➖ Required permissions ➖ ReadContacts
Or in your AssemblyInfo.cs file under the Properties folder and add the following code:
For IOS and UWP you don’t need an additional configuration.
What is Contacts.PickContactAsync()?
It’s the method that opens a user dialog and allow us to pick information of a specific user from a device.
What Contact information do we can obtain?
We have a lot of contact information to use! Let’s explore it!
To better understand, let’s see is a real contact where we will identify each of the information that we can obtain. Finally, we add a short code example of how we can obtain it to develop our applications.
⚠ The iOS platform does not support the
DisplayName property natively, that’s why this value is constructed as “GivenName + FamilyName”. In this case: Jessy Morris.
Getting all contacts 🎯
If you want to get all the contact that you have on the device, you can do it! In this case, let’s use Contacts.GetAllAsync() ins
GetAllAsync the method is only used on UWP.
From here you can handle the data obtained as you like!
Thanks for reading 💚💕!!