Parameters
| Property | Type | Required | Description |
|---|---|---|---|
| photoFilePath | String | No | Local file path of avatar |
| nickName | String | No | Nickname |
| lastName | String | No | Surname |
| middleName | String | No | Middle name |
| firstName | String | No | First name |
| remark | String | No | Remarks |
| mobilePhoneNumber | String | No | Cell number |
| addressCountry | String | No | Country in contact address |
| addressState | String | No | Province in contact address |
| addressCity | String | No | City in contact address |
| addressStreet | String | No | Street in contact address |
| addressPostalCode | String | No | Postcode in contact address |
| organization | String | No | Company |
| title | String | No | Title |
| workFaxNumber | String | No | Work fax |
| workPhoneNumber | String | No | Work phone number |
| hostNumber | String | No | Company phone number |
| String | No | ||
| url | String | No | Website |
| workAddressCountry | String | No | Country in work address |
| workAddressState | String | No | Province in work address |
| workAddressCity | String | No | City in work address |
| workAddressStreet | String | No | Street in work address |
| workAddressPostalCode | String | No | Postcode in work address |
| homeFaxNumber | String | No | Home fax |
| homePhoneNumber | String | No | Home phone |
| homeAddressCountry | String | No | Country in home address |
| homeAddressState | String | No | Province in home address |
| homeAddressCity | String | No | City in home address |
| homeAddressStreet | String | No | Street in home address |
| homeAddressPostalCode | String | No | Postcode in home address |
| success | Function | No | Callback on success |
| fail | Function | No | Callback on failure |
| complete | Function | No | Callback that always executes |
Error Codes
| Error | Message | Description |
|---|---|---|
| 11 | fail cancel | The user cancels the operation. |
| 3 | fail $ | Call failure, detail includes the detailed information. |
Code Example
Basic Usage
my.addPhoneContact({
firstName: 'John',
lastName: 'Doe',
mobilePhoneNumber: '+1234567890',
success() {
my.showToast({ content: 'Contact added' });
}
});
Business Contact
my.addPhoneContact({
firstName: 'Jane',
lastName: 'Smith',
mobilePhoneNumber: '+1234567890',
workPhoneNumber: '+1987654321',
email: 'jane.smith@example.com',
organization: 'Acme Corporation',
title: 'Sales Manager',
workAddressStreet: '123 Business Ave',
workAddressCity: 'New York',
workAddressState: 'NY',
workAddressPostalCode: '10001',
workAddressCountry: 'USA',
success() {
my.showToast({ content: 'Contact saved successfully' });
},
fail(err) {
my.showToast({ content: 'Failed to save contact', type: 'fail' });
}
});
Add Store Contact
Page({
data: {
store: {
name: 'Downtown Store',
phone: '+1234567890',
address: '456 Main Street',
city: 'Los Angeles'
}
},
saveStoreContact() {
const { store } = this.data;
my.addPhoneContact({
firstName: store.name,
mobilePhoneNumber: store.phone,
workAddressStreet: store.address,
workAddressCity: store.city,
remark: 'Added from Mini Program',
success() {
my.showToast({ content: 'Store contact saved' });
}
});
}
});
The user will always see a system confirmation dialog before the contact is actually added. This protects user privacy and prevents unwanted contacts.
Related APIs
my.choosePhoneContact
Choose from contacts
my.makePhoneCall
Make phone call