my.choosePhoneContact

Select the phone number of a contact in the local system directory.

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.choosePhoneContact</view>
        <view class="page-section-demo">
          <button type="primary" onTap="choosePhoneContact">Evoke local directory</button>
        </view>
      </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="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="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="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="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="00000" />
            </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="000000" />
            </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": "00000",
          "workAddressCountry": "work country",
          "workAddressState": "work state",
          "workAddressCity": "work city",
          "workAddressStreet": "work street",
          "workAddressPostalCode": "000000",
          "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)
            });
          }
      },
      choosePhoneContact() {
        my.choosePhoneContact({
          success: (res) => {
            my.alert({
              content: 'choosePhoneContact response: ' + JSON.stringify(res)
            });
          },
          fail: (res) => {
            my.alert({
              content: 'choosePhoneContact 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:

AttributesTypeMandatoryDescription
successFunctionNoCallback function for call success
failFunctionNoCallback function for call failure
completeFunctionNoCallback function for call completion (to be executed for both call success and failure)

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

AttributesTypeDescription
nameStringSelected contact name
mobileStringSelected contact phone

Error Code

Error codeDescription
10No permission
11The user cancels the operation (or the device does not authorize use of the directory).