Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Read First and Last names from Android Contacts

$
0
0

I'm trying to read the first and last names from Android contacts:
` var projection = new string[]
{
ContactsContract.CommonDataKinds.Phone.InterfaceConsts.DisplayName,
ContactsContract.CommonDataKinds.StructuredName.GivenName,
};
var whereClause = ContactsContract.CommonDataKinds.Phone.InterfaceConsts.HasPhoneNumber + " != 0";
var app = Resolver.Resolve() as IXFormsApp;
var loader = new CursorLoader(app.AppContext, ContactsContract.CommonDataKinds.Phone.ContentUri, projection, whereClause, null, null);
var cursor = (ICursor)loader.LoadInBackground();

        while (cursor.MoveToNext())
        {
            var displayName = cursor.GetString(cursor.GetColumnIndex(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.DisplayName));
            var firstName = cursor.GetString(cursor.GetColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GivenName));
        }`

This gets me the display name just fine, but firstName is always "2"
I'm guessing I'm looking at the wrong URI. I've tried a couple of others. ContactsContract.Data.ContentUri gives similar results while ContactsContract.Contacts.ContentLookupUri crashes. What do I need to do to get the structuredName?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>