Xamarin Forms Reading Contacts

Reading Contacts in Xamarin Forms

In this article, I’ll present to you how to read contacts from Portable Layer in Xamarin Forms. I’ve already created codes and you’ll use only one line code like this:

var contacts = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync();

Sample Project

Just create a new project and add Xamarin.Forms.Contacts NuGet package to all Layers

Xamarin Forms Contacts Enis Necipoglu Android iOS Read Contacts
Xamarin Forms Contacts Enis Necipoglu Android iOS Read Contacts

We’ll use MainPage which comes from new project as default. Firsly add a listview to MainPage.XAML and go MainPage.Cs and add reading code which I read at top of article and bind it

PERMISSIONS

Most important part is Permissions. Don’t forget to set permissions for each platform.

For Android, you can add permission to AndroidManifes.xml manually but my suggestion is, right click the Android project and click Properties than go Android Manifest tab, you’ll see permissions windows that allows you set permissons via checkboxes. Just check READ_CONTACTS permission.

For iOS, Right click the Info.plist and choose Open With opiton. Select XML Editor from there and add NSContactsUsageDescription as key and add a description between string tags why you want this permisson below the key into dict tags. (Sample is below.)



PROJECT FILES


Possible Mistakes:

  • Over Android 5.0 versions you need to request Runtime Permissons to reach contact data.
  • Users won’t give permission for contacts. You can use Permission Plugin to avoid unexpected situations.
label, , , , , ,

3 Comments

  1. Alireza 29 May 2018 Reply
  2. Madboy 20 September 2018 Reply
  3. Eric Jones 17 March 2021 Reply

Add a Comment

Your email address will not be published. Required fields are marked *