my.addPhoneContact
Version requirements: Basic library 1.10.0 or higher version. If the version is low, suggest Compatible treatment
This form enables the user to write the form into phone contacts via create contacts or add to existing contacts.
Sample Code
copy
// API-DEMO page/API/contact/contact.json
{
"defaultTitle": "Contact"
}
copy
<!-- API-DEMO page/API/contact/contact.axml-->
<view class="page">
<view class="page-description">Contact API</view>
<view class="page-section">
<view class="page-section-title">my.addPhoneContact</view>
<view class="page-section-demo">
<view style="font-size:18px;margin-top:18px;margin-bottom:18px">
<text style="font-size:18px;margin-top:18px;margin-bottom:18px">Basic information</text>
</view>
<view class="form-row">
<view class="form-row-label">Nickname</view>
<view class="form-row-content">
<input id="nickName" onInput="onInput" class="input" value="Baking July" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Last name</view>
<view class="form-row-content">
<input id="lastName" onInput="onInput" class="input" value="Last" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Middle name</view>
<view class="form-row-content">
<input id="middleName" onInput="onInput" class="input" value="Middle" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">First name</view>
<view class="form-row-content">
<input id="firstName" onInput="onInput" class="input" value="First" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Remarks</view>
<view class="form-row-content">
<input id="remark" onInput="onInput" class="input" value="This is the remarks" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Phone number</view>
<view class="form-row-content">
<input id="mobilePhoneNumber" onInput="onInput" class="input" value="13800000000" />
</view>
</view>
<view style="font-size:18px;margin-top:18px;margin-bottom:18px">
<text style="font-size:18px;margin-top:18px;margin-bottom:18px">Contact address</text>
</view>
<view class="form-row">
<view class="form-row-label">Country</view>
<view class="form-row-content">
<input id="addressCountry" onInput="onInput" class="input" value="address country" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Province</view>
<view class="form-row-content">
<input id="addressState" onInput="onInput" class="input" value="address state" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">City</view>
<view class="form-row-content">
<input id="addressCity" onInput="onInput" class="input" value="address city" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Street</view>
<view class="form-row-content">
<input id="addressStreet" onInput="onInput" class="input" value="address street" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Postcode</view>
<view class="form-row-content">
<input id="addressPostalCode" onInput="onInput" class="input" value="94016" />
</view>
</view>
<view style="font-size:18px;margin-top:18px;margin-bottom:18px">
<text style="font-size:18px;margin-top:18px;margin-bottom:18px">Work</text>
</view>
<view class="form-row">
<view class="form-row-label">Company</view>
<view class="form-row-content">
<input id="organization" onInput="onInput" class="input" value="organization" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Title</view>
<view class="form-row-content">
<input id="title" onInput="onInput" class="input" value="Developer" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Work fax</view>
<view class="form-row-content">
<input id="workFaxNumber" onInput="onInput" class="input" value="11111111" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Work phone</view>
<view class="form-row-content">
<input id="workPhoneNumber" onInput="onInput" class="input" value="11111112" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Company phone</view>
<view class="form-row-content">
<input id="hostNumber" onInput="onInput" class="input" value="11111113" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Email</view>
<view class="form-row-content">
<input id="email" onInput="onInput" class="input" value="liuhuo01@miniprogram.com" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Website</view>
<view class="form-row-content">
<input id="url" onInput="onInput" class="input" value="www.miniprogram.com" />
</view>
</view>
<view style="font-size:18px;margin-top:18px;margin-bottom:18px">
<text style="font-size:18px;margin-top:18px;margin-bottom:18px">Company address</text>
</view>
<view class="form-row">
<view class="form-row-label">Country</view>
<view class="form-row-content">
<input id="workAddressCountry" onInput="onInput" class="input" value="work country" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Province</view>
<view class="form-row-content">
<input id="workAddressState" onInput="onInput" class="input" value="work state" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">City</view>
<view class="form-row-content">
<input id="workAddressCity" onInput="onInput" class="input" value="work city" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Street</view>
<view class="form-row-content">
<input id="workAddressStreet" onInput="onInput" class="input" value="work street" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Postcode</view>
<view class="form-row-content">
<input id="workAddressPostalCode" onInput="onInput" class="input" value="111111" />
</view>
</view>
<view style="font-size:18px;margin-top:18px;margin-bottom:18px">
<text style="font-size:18px;margin-top:18px;margin-bottom:18px">Home</text>
</view>
<view class="form-row">
<view class="form-row-label">Fax</view>
<view class="form-row-content">
<input id="homeFaxNumber" onInput="onInput" class="input" value="11111114" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Phone</view>
<view class="form-row-content">
<input id="homePhoneNumber" onInput="onInput" class="input" value="11111115" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Country</view>
<view class="form-row-content">
<input id="homeAddressCountry" onInput="onInput" class="input" value="home country" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Province</view>
<view class="form-row-content">
<input id="homeAddressState" onInput="onInput" class="input" value="home state" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">City</view>
<view class="form-row-content">
<input id="homeAddressCity" onInput="onInput" class="input" value="home city" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Street</view>
<view class="form-row-content">
<input id="homeAddressStreet" onInput="onInput" class="input" value="home street" />
</view>
</view>
<view class="form-row">
<view class="form-row-label">Postcode</view>
<view class="form-row-content">
<input id="homeAddressPostalCode" onInput="onInput" class="input" value="123456" />
</view>
</view>
<button type="primary" onTap="addPhoneContact">Add to phone contact</button>
</view>
</view>
</view>
copy
// API-DEMO page/API/contact/contact.js
Page({
data:{
"photoFilePath": "/sdcard/DCIM/Camera/a.jpg",
"nickName": "Baking July",
"lastName": "Last",
"middleName": "Middle",
"firstName": "First",
"remark": "This is remarks",
"mobilePhoneNumber": "13800000000",
"homePhoneNumber": "11111115",
"workPhoneNumber": "11111112",
"homeFaxNumber": "11111114",
"workFaxNumber": "11111111",
"hostNumber": "11111113",
"addressCountry": "address country",
"addressState": "address state",
"addressCity": "address city",
"addressStreet": "address street",
"addressPostalCode": "94016",
"workAddressCountry": "work country",
"workAddressState": "work state",
"workAddressCity": "work city",
"workAddressStreet": "work street",
"workAddressPostalCode": "111111",
"homeAddressCountry": "home country",
"homeAddressState": "home state",
"homeAddressCity": "home city",
"homeAddressStreet": "home street",
"homeAddressPostalCode": "123456",
"organization": "organization",
"title": "Developer",
"email": "liuhuo01@miniprogram.com",
"url": "www.miniprogram.com",
success: (res) => {
my.alert({
content: 'addPhoneContact response: ' + JSON.stringify(res)
});
},
fail: (res) => {
my.alert({
content: 'addPhoneContact response: ' + JSON.stringify(res)
});
}
},
onInput(e) {
this.data[e.currentTarget.id] = e.detail.value;
},
addPhoneContact() {
if (my.canIUse('addPhoneContact')) {
my.addPhoneContact(this.data);
} else {
my.alert({
title: 'Client version too low',
content: 'my.addPhoneContact() needs higher version'
});
}
}
});
Parameters
Object type with the following attributes:
Attributes | Type | Mandatory | 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 function for call success |
fail | Function | No | Callback function for call failure |
complete | Function | No | Callback function for call completion (to be executed for both call success and failure) |
Depending on the support of contact App built in different ROM, the above fields may not support emoji or kaomoji. In such cases, this option is ignored.
Return Value
Success:
success = true
Failure:
error | errorMessage | Description |
11 | fail cancel | The user cancels the operation. |
3 | fail ${detail} | Call failure, detail includes the detailed information. |