Save the information of a contact in android xamarin

1
void button_Click(object sender, EventArgs e)
    {
        //Create a new intent for choosing a contact
        var contactPickerIntent = new Intent(Intent.ActionPick,
            Android.Provider.ContactsContract.CommonDataKinds.Email.ContentUri);
        //Start the contact picker expecting a result
        // with the resultCode '101'
        StartActivityForResult(contactPickerIntent,101);   // mostra a lista dos contactos do telefone, so com as pessoas com email.
    }

My code is this, when I click the button it appears to me all the contacts of the user with email. And what I wanted was to know how to store this information, for example the user selects a person from their contacts and I want to send an email to that person, but for this I need to save the contact information and this is what I do not know how to do .

Thanks to anyone who can help.

    
asked by anonymous 04.05.2016 / 13:35

1 answer

0

Override the OnActivityResult method, where on the date it will return the information of the selected contact as in the following example:

protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);

    var cursor = ContentResolver.Query(data.Data, null, null, null, null);
    cursor.MoveToFirst();

    var columnNumber = cursor.GetColumnIndex(Phone.Number);
    var phoneNumber = cursor.GetString(columnNumber);

    var columnName = cur.GetColumnIndex(ContactsContract.ContactNameColumns.DisplayNamePrimary);
    var name = cursor.GetString(columnName);
}
    
04.05.2016 / 14:42