I need to programmatically open the android contacts app using an intent with Xamarin Forms/Android. When the Add New Contact activity/screen comes up, I would like to pre-populate it with the following fields:
- Name (this is populating)
- Phone (this is populating)
- Street (Not populating)
- City (Not populating)
- State (Not populating)
- Country (Not seeing a field for this, not populating)
As stated above, some screens are populating, but the address fields are not. This is the Xamarin C# Android code/service being used to trigger the activity for opening up Android's 'Add Contact' screen:
public void AddContact(string name, string[] phoneNumbers, string streetAddress, string city, string state, string postalCode, CountryValues countrycode)
{
// get current activity
var activity = CrossCurrentActivity.Current.Activity;
// create add contact intent
var intent = new Intent(Intent.ActionInsert);
intent.SetType(ContactsContract.Contacts.ContentType);
// add field for contact name
intent.PutExtra(ContactsContract.Intents.Insert.Name, name);
// Adding more than on phone number if available
foreach (string numbers in phoneNumbers)
{
intent.PutExtra(ContactsContract.Intents.Insert.Phone, numbers);
}
// pre-populate address fields
intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Street, streetAddress);
intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.City, city);
intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Region, state);
intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Postcode, postalCode);
intent.PutExtra(ContactsContract.CommonDataKinds.StructuredPostal.Country, countrycode.ToString());
//start activity
activity.StartActivity(intent);
}
The activity does open the 'add new contact' screen in the contacts app, but only the name and the phone number fields are populated. See screenshots below:
I found a link that may translate into Xamarin.Android but I have been struggling with the implementation Java Samples.