Forum Xamarin.Android

I can't set phone number type/label in native Android Contact via ContentProvider

I can add to contact phone number but I can't set number type like mobile or home. And type always set custom.
Here code that I am using:
void AddPhoneToContact(List ops, int rawContactInsertIndex, string phone, string title)
{
ops.Add(GetCreateContactBuilder(rawContactInsertIndex)
.WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, ContactsContract.CommonDataKinds.Phone.ContentItemType)
.WithValue(ContactsContract.CommonDataKinds.Phone.Number, phone) // Number of the person
.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, "Home")
.WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Home")
.Build());
}
What am I doing wrong?

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    You can try the following code:

     void AddPhoneToContact(List ops, int rawContactInsertIndex, string phone, string title)
    {
       ops.Add(GetCreateContactBuilder(rawContactInsertIndex)
       .WithValue(ContactsContract.Data.InterfaceConsts.Mimetype, 
      ContactsContract.CommonDataKinds.Phone.ContentItemType)
     .WithValue(ContactsContract.CommonDataKinds.Phone.Number, phone) // Number of the person
     .WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                    ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom)
     .WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Label, "Home")
    .Build());
     }
    

    Note: Just to change

     .WithValue(ContactsContract.CommonDataKinds.Phone.InterfaceConsts.Type, "Home")
    

    to

       .WithValue(ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.Type,
                    ContactsContract.CommonDataKinds.StructuredPostal.InterfaceConsts.TypeCustom)
    
Sign In or Register to comment.