I am creating a hybrid mobile app, using Xamarin.Forms.
I want the user to click a button and the contact in the app gets inserted into the phone's contacts, including the profile picture.
So far, everything on the iOS side is working. I successfully insert the profile picture.
I can't get it to work on Android though. I've already tried looking on here but all solutions use Java. Inserting the name, number and e-mail works perfectly.
Here is my code so far:
public void SaveContacts(string name, string number, string email, string job, string company, byte[] imageData)
{
try
{
var intent = new Intent(Intent.ActionInsert);
intent.SetType(ContactsContract.Contacts.ContentType);
if (!string.IsNullOrWhiteSpace(name))
intent.PutExtra(ContactsContract.Intents.Insert.Name, name);
if (!string.IsNullOrWhiteSpace(number))
intent.PutExtra(ContactsContract.Intents.Insert.Phone, number);
if (!string.IsNullOrWhiteSpace(email))
intent.PutExtra(ContactsContract.Intents.Insert.Email, email);
if (imageData.Length != 0)
{
// INSERT PROFILE PICTURE HERE
}
Platform.CurrentActivity.StartActivity(intent);
}
catch (Exception ex)
{
DependencyService.Get<ILogger>()?.Error(ex);
}
}
How do I add the profile picture to the contact?