Device APIs

addPhoneContact

Add a contact to the user's phone via a form or pre-filled data.

Overview

my.addPhoneContact lets users add a contact to their phone—either by filling a form (create new or add to existing) or by passing contact data from your Mini Program. All contact fields are optional; only the ones you provide are used.

Sample Code

HTML

<button onclick="addContact()">Add to phone contacts</button>

JavaScript

function addContact() {
  if (!my.canIUse("addPhoneContact")) {
    my.alert({
      title: "Client version too low",
      content: "my.addPhoneContact() requires a higher version.",
    });
    return;
  }

  my.addPhoneContact({
    nickName: "Baking July",
    lastName: "Last",
    middleName: "Middle",
    firstName: "First",
    remark: "This is remarks",
    mobilePhoneNumber: "13000000000",
    success: (res) => {
      my.alert({ content: "addPhoneContact response: " + JSON.stringify(res) });
    },
    fail: (res) => {
      my.alert({ content: "addPhoneContact failed: " + JSON.stringify(res) });
    },
  });
}

Parameters

Object type with the following attributes. All contact fields are optional.

PropertyTypeRequiredDescription
photoFilePathStringNoLocal file path of avatar.
nickNameStringNoNickname.
lastNameStringNoSurname.
middleNameStringNoMiddle name.
firstNameStringNoFirst name.
remarkStringNoRemarks.
mobilePhoneNumberStringNoCell number.
homePhoneNumberStringNoHome phone.
workPhoneNumberStringNoWork phone.
homeFaxNumberStringNoHome fax.
workFaxNumberStringNoWork fax.
hostNumberStringNoCompany phone number.
addressCountryStringNoCountry in contact address.
addressStateStringNoProvince in contact address.
addressCityStringNoCity in contact address.
addressStreetStringNoStreet in contact address.
addressPostalCodeStringNoPostcode in contact address.
workAddressCountryStringNoCountry in work address.
workAddressStateStringNoProvince in work address.
workAddressCityStringNoCity in work address.
workAddressStreetStringNoStreet in work address.
workAddressPostalCodeStringNoPostcode in work address.
homeAddressCountryStringNoCountry in home address.
homeAddressStateStringNoProvince in home address.
homeAddressCityStringNoCity in home address.
homeAddressStreetStringNoStreet in home address.
homeAddressPostalCodeStringNoPostcode in home address.
organizationStringNoCompany.
titleStringNoJob title.
emailStringNoEmail.
urlStringNoWebsite.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion.
Depending on the contact app and device ROM, some fields may not support emoji or kaomoji; in such cases the option is ignored.

Return Value

Success: Callback receives an object with success: true.

Failure: Callback receives an error object. Common cases:

ErrorDescription
11User cancelled the operation.
2Call failure; detail includes more information.