Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

how to get email address xamarin?

StanislavPStanislavP USMember
edited June 2016 in Xamarin.Android

Hello, guys!

I try to read contacts info in my test app. Names and PhoneNumbers are read normally, but email address is not. Instead, the address number is read.
Here is my code:

`var uri = ContactsContract.CommonDataKinds.Phone.ContentUri;

        string[] projection = { 
            ContactsContract.Contacts.InterfaceConsts.DisplayName, ContactsContract.CommonDataKinds.Phone.Number ,
            ContactsContract.CommonDataKinds.Email.Address};
        var loader = new CursorLoader (_context, uri, projection, null, null, null);
        var cursor = (Android.Database.ICursor)loader.LoadInBackground();
        var contactList = new List<Contact> ();
        if (cursor.MoveToFirst ()) {
            do {
                contactList.Add (new Contact(
                    cursor.GetString (cursor.GetColumnIndex (projection [0])),
                    cursor.GetString (cursor.GetColumnIndex (projection [1])),
                    cursor.GetString (cursor.GetColumnIndex (projection [2]))
                ));
            }  while (cursor.MoveToNext());

        return new ContactsAdapter (_context, contactList);
        }`

Maybe anyone can help me....?

Best Answer

Answers

  • soumenhaldersoumenhalder Member ✭✭✭
    edited February 2020

    @StanislavP
    This is working perfect. Now can you please suggest me how to get the contact's first name, middle name, last name instead of display name?

Sign In or Register to comment.