From 65f93581a93adf76626741958d6f3849db781f1c Mon Sep 17 00:00:00 2001 From: shawn_he Date: Mon, 16 May 2022 15:34:21 +0800 Subject: [PATCH] update docs Signed-off-by: shawn_he --- .../reference/apis/js-apis-call.md | 38 ++--- .../reference/apis/js-apis-contact.md | 160 +++++++++--------- .../reference/apis/js-apis-http.md | 24 +-- .../reference/apis/js-apis-net-connection.md | 60 +++---- .../reference/apis/js-apis-observer.md | 38 ++--- .../reference/apis/js-apis-radio.md | 40 ++--- .../reference/apis/js-apis-sim.md | 40 ++--- .../reference/apis/js-apis-sms.md | 22 +-- .../reference/apis/js-apis-socket.md | 78 ++++----- .../reference/apis/js-apis-webSocket.md | 38 ++--- 10 files changed, 269 insertions(+), 269 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-call.md b/en/application-dev/reference/apis/js-apis-call.md index 4d2b6c07f8..cda24e954d 100644 --- a/en/application-dev/reference/apis/js-apis-call.md +++ b/en/application-dev/reference/apis/js-apis-call.md @@ -7,7 +7,7 @@ ## Modules to Import -``` +```js import call from '@ohos.telephony.call'; ``` @@ -30,7 +30,7 @@ Initiates a call. This API uses an asynchronous callback to return the execution **Example** -``` +```js call.dial("138xxxxxxxx", (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -57,7 +57,7 @@ Initiates a call. You can set call options as needed. This API uses an asynchron **Example** -``` +```js call.dial("138xxxxxxxx", { extras: false }, (err, data) => { @@ -91,7 +91,7 @@ Initiates a call. You can set call options as needed. This API uses a promise to **Example** -``` +```js let promise = call.dial("138xxxxxxxx", { extras: false }); @@ -121,7 +121,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a **Example** -``` +```js call.makeCall("138xxxxxxxx", err => { console.log(`makeCall callback: err->${JSON.stringify(err)}`); }); @@ -152,7 +152,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a **Example** -``` +```js let promise = call.makeCall("138xxxxxxxx"); promise.then(() => { console.log(`makeCall success`); @@ -177,7 +177,7 @@ Checks whether a call is in progress. This API uses an asynchronous callback to **Example** -``` +```js call.hasCall((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -200,7 +200,7 @@ Checks whether a call is in progress. This API uses a promise to return the resu **Example** -``` +```js let promise = call.hasCall(); promise.then(data => { console.log(`hasCall success, promise: data->${JSON.stringify(data)}`); @@ -226,7 +226,7 @@ Obtains the call status. This API uses an asynchronous callback to return the re **Example** -``` +```js call.getCallState((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -249,7 +249,7 @@ Obtains the call status. This API uses a promise to return the result. **Example** -``` +```js let promise = call.getCallState(); promise.then(data => { console.log(`getCallState success, promise: data->${JSON.stringify(data)}`); @@ -272,7 +272,7 @@ Checks whether a device supports voice calls. This API works in synchronous mode | ------- | ------------------------------------------------------------ | | boolean | - **true**: The device supports voice calls.
- **false**: The device does not support voice calls.| -``` +```js let result = call.hasVoiceCapability(); console.log(`hasVoiceCapability: ${JSON.stringify(result)}`); ``` @@ -294,7 +294,7 @@ Checks whether the call number of the SIM card in the specified slot is an emerg **Example** -``` +```js call.isEmergencyPhoneNumber("138xxxxxxxx", (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -319,7 +319,7 @@ Checks whether the call number of the SIM card in the specified slot is an emerg **Example** -``` +```js call.isEmergencyPhoneNumber("112", {slotId: 1}, (err, value) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -349,7 +349,7 @@ Checks whether the call number of the SIM card in the specified slot is an emerg **Example** -``` +```js let promise = call.isEmergencyPhoneNumber("138xxxxxxxx", {slotId: 1}); promise.then(data => { console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`); @@ -375,7 +375,7 @@ Formats a phone number based on the specified ISO country code. This API uses an **Example** -``` +```js call.formatPhoneNumber("138xxxxxxxx", (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -400,7 +400,7 @@ Formats a phone number based on specified formatting options. This API uses an a **Example** -``` +```js call.formatPhoneNumber("138xxxxxxxx",{ countryCode: "CN" }, (err, data) => { @@ -432,7 +432,7 @@ Formats a phone number based on specified formatting options. This API uses a pr **Example** -``` +```js let promise = call.formatPhoneNumber("138xxxxxxxx", { countryCode: "CN" }); @@ -465,7 +465,7 @@ All country codes are supported. **Example** -``` +```js call.formatPhoneNumberToE164("138xxxxxxxx",{ countryCode: "CN" }, (err, data) => { @@ -501,7 +501,7 @@ All country codes are supported. **Example** -``` +```js let promise = call.formatPhoneNumberToE164("138xxxxxxxx", { countryCode: "CN" }); diff --git a/en/application-dev/reference/apis/js-apis-contact.md b/en/application-dev/reference/apis/js-apis-contact.md index 9a4574e069..610f802066 100644 --- a/en/application-dev/reference/apis/js-apis-contact.md +++ b/en/application-dev/reference/apis/js-apis-contact.md @@ -7,7 +7,7 @@ ## Modules to Import -``` +```js import contact from '@ohos.contact'; ``` @@ -29,7 +29,7 @@ Adds a contact. This API uses an asynchronous callback to return the result. **Example** - ``` + ```js contact.addContact({ fullName: {fullName: 'xxx'}, phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] @@ -65,7 +65,7 @@ Adds a contact. This API uses a promise to return the result. **Example** - ``` + ```js let promise = contact.addContact({ name: {fullName: 'xxx'}, phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] @@ -96,7 +96,7 @@ Deletes a contact based on the specified contact key. This API uses an asynchron **Example** - ``` + ```js contact.deleteContact('xxx', (err) => { if (err) { console.log(`deleteContact callback: err->${JSON.stringify(err)}`); @@ -129,7 +129,7 @@ Deletes a contact based on the specified contact key. This API uses a promise to **Example** - ``` + ```js let promise = contact.deleteContact('xxx'); promise.then(() => { console.log(`deleteContact success`); @@ -157,7 +157,7 @@ Updates a contact based on the specified contact information. This API uses an a **Example** - ``` + ```js contact.updateContact({ name: {fullName: 'xxx'}, phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] @@ -190,7 +190,7 @@ Updates a contact based on the specified contact information and attributes. Thi **Example** - ``` + ```js contact.updateContact({ fullName: {fullName: 'xxx'}, phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] @@ -229,7 +229,7 @@ Updates a contact based on the specified contact information and attributes. Thi **Example** - ``` + ```js let promise = contact.updateContact({ fullName: {fullName: 'xxx'}, phoneNumbers: [{phoneNumber: '138xxxxxxxx'}] @@ -262,7 +262,7 @@ Checks whether the ID of this contact is in the local address book. This API use **Example** - ``` + ```js contact.isLocalContact(/*id*/1, (err, data) => { if (err) { console.log(`isLocalContact callback: err->${JSON.stringify(err)}`); @@ -295,7 +295,7 @@ Checks whether the ID of this contact is in the local address book. This API use **Example** - ``` + ```js let promise = contact.isLocalContact(/*id*/1); promise.then((data) => { console.log(`isLocalContact success: data->${JSON.stringify(data)}`); @@ -323,7 +323,7 @@ Checks whether a contact is included in my card. This API uses an asynchronous c **Example** - ``` + ```js contact.isMyCard(/*id*/1, (err, data) => { if (err) { console.log(`isMyCard callback: err->${JSON.stringify(err)}`); @@ -356,7 +356,7 @@ Checks whether a contact is included in my card. This API uses a promise to retu **Example** - ``` + ```js let promise = contact.isMyCard(/*id*/1); promise.then((data) => { console.log(`isMyCard success: data->${JSON.stringify(data)}`); @@ -383,7 +383,7 @@ Queries my card. This API uses an asynchronous callback to return the result. **Example** - ``` + ```js contact.queryMyCard((err, data) => { if (err) { console.log(`queryMyCard callback: err->${JSON.stringify(err)}`); @@ -412,7 +412,7 @@ Queries my card based on the specified contact attributes. This API uses an asyn **Example** - ``` + ```js contact.queryMyCard({ attributes:['ATTR_EMAIL', 'ATTR_NAME'] }, (err, data) => { @@ -447,7 +447,7 @@ Queries my card based on the specified contact attributes. This API uses a promi **Example** - ``` + ```js let promise = contact.queryMyCard({ attributes:['ATTR_EMAIL', 'ATTR_NAME'] }); @@ -478,7 +478,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a **Example** - ``` + ```js contact.selectContact((err, data) => { if (err) { console.log(`selectContact callback: err->${JSON.stringify(err)}`); @@ -508,7 +508,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a **Example** - ``` + ```js let promise = contact.selectContact(); promise.then((data) => { console.log(`selectContact success: data->${JSON.stringify(data)}`); @@ -536,7 +536,7 @@ Queries a contact based on the specified key. This API uses an asynchronous call **Example** - ``` + ```js contact.queryContact('xxx', (err, data) => { if (err) { console.log(`queryContact callback: err->${JSON.stringify(err)}`); @@ -566,7 +566,7 @@ Queries contacts based on the specified key and application. This API uses an as **Example** - ``` + ```js contact.queryContact('xxx', { holderId: 0 }, (err, data) => { @@ -598,7 +598,7 @@ Queries contacts based on the specified key and attributes. This API uses an asy **Example** - ``` + ```js contact.queryContact('xxx', { attributes: ["ATTR_EMAIL", "ATTR_NAME"] }, (err, data) => { @@ -631,7 +631,7 @@ Queries contacts based on the specified key, application, and attributes. This A **Example** - ``` + ```js contact.queryContact('xxx', { holderId: 0 }, { @@ -670,7 +670,7 @@ Queries contacts based on the specified key, application, and attributes. This A **Example** - ``` + ```js let promise = contact.queryContact('xxx', { holderId: 0 }, { @@ -701,7 +701,7 @@ Queries all contacts. This API uses an asynchronous callback to return the resul **Example** - ``` + ```js contact.queryContacts((err, data) => { if (err) { console.log(`queryContacts callback: err->${JSON.stringify(err)}`); @@ -730,7 +730,7 @@ Queries all contacts based on the specified application. This API uses an asynch **Example** - ``` + ```js contact.queryContacts({ holderId: 0 }, (err, data) => { @@ -761,7 +761,7 @@ Queries all contacts based on the specified attributes. This API uses an asynchr **Example** - ``` + ```js contact.queryContacts({ attributes: ["ATTR_EMAIL", "ATTR_NAME"] }, (err, data) => { @@ -793,7 +793,7 @@ Queries all contacts based on the specified application and attributes. This API **Example** - ``` + ```js contact.queryContacts({ holderId: 0 }, { @@ -831,7 +831,7 @@ Queries all contacts based on the specified application and attributes. This API **Example** - ``` + ```js let promise = contact.queryContacts({ holderId: 0 }, { @@ -863,7 +863,7 @@ Queries contacts based on the specified phone number. This API uses an asynchron **Example** - ``` + ```js contact.queryContactsByPhoneNumber('138xxxxxxxx', (err, data) => { if (err) { console.log(`queryContactsByPhoneNumber callback: err->${JSON.stringify(err)}`); @@ -893,7 +893,7 @@ Queries contacts based on the specified phone number and application. This API u **Example** - ``` + ```js contact.queryContactsByPhoneNumber('138xxxxxxxx', { holderId: 0 }, (err, data) => { @@ -925,7 +925,7 @@ Queries contacts based on the specified phone number and attributes. This API us **Example** - ``` + ```js contact.queryContactsByPhoneNumber('138xxxxxxxx', { attributes: ["ATTR_EMAIL", "ATTR_NAME"] }, (err, data) => { @@ -958,7 +958,7 @@ Queries contacts based on the specified phone number, application, and attribute **Example** - ``` + ```js contact.queryContactsByPhoneNumber('138xxxxxxxx', { holderId: 0 }, { @@ -997,7 +997,7 @@ Queries contacts based on the specified phone number, application, and attribute **Example** - ``` + ```js let promise = contact.queryContactsByPhoneNumber('138xxxxxxxx', { holderId: 0 }, { @@ -1029,7 +1029,7 @@ Queries contacts based on the specified email address. This API uses an asynchro **Example** - ``` + ```js contact.queryContactsByEmail('xxx@email.com', (err, data) => { if (err) { console.log(`queryContactsByEmail callback: err->${JSON.stringify(err)}`); @@ -1059,7 +1059,7 @@ Queries contacts based on the specified email address and application. This API **Example** - ``` + ```js contact.queryContactsByEmail('xxx@email.com', { holderId: 0 }, (err, data) => { @@ -1091,7 +1091,7 @@ Queries contacts based on the specified email address and attributes. This API u **Example** - ``` + ```js contact.queryContactsByEmail('xxx@email.com', { attributes: ["ATTR_EMAIL", "ATTR_NAME"] }, (err, data) => { @@ -1124,7 +1124,7 @@ Queries contacts based on the specified email address, application, and attribut **Example** - ``` + ```js contact.queryContactsByEmail('xxx@email.com', { holderId: 0 }, { @@ -1163,7 +1163,7 @@ Queries contacts based on the specified email address, application, and attribut **Example** - ``` + ```js let promise = contact.queryContactsByEmail('xxx@email.com', { holderId: 0 }, { @@ -1194,7 +1194,7 @@ Queries all groups of this contact. This API uses an asynchronous callback to re **Example** - ``` + ```js contact.queryGroups((err, data) => { if (err) { console.log(`queryGroups callback: err->${JSON.stringify(err)}`); @@ -1223,7 +1223,7 @@ Queries all groups of this contact based on the specified application. This API **Example** - ``` + ```js contact.queryGroups({ holderId: 0 }, (err, data) => { @@ -1258,7 +1258,7 @@ Queries all groups of this contact based on the specified application. This API **Example** - ``` + ```js let promise = contact.queryGroups({ holderId: 0 }); @@ -1287,7 +1287,7 @@ Queries all applications that have created contacts. This API uses an asynchrono **Example** - ``` + ```js contact.queryHolders((err, data) => { if (err) { console.log(`queryHolders callback: err->${JSON.stringify(err)}`); @@ -1315,7 +1315,7 @@ Queries all applications that have created contacts. This API uses a promise to **Example** - ``` + ```js let promise = contact.queryHolders(); promise.then((data) => { console.log(`queryHolders success: data->${JSON.stringify(data)}`); @@ -1343,7 +1343,7 @@ Queries the key of a contact based on the specified contact ID. This API uses an **Example** - ``` + ```js contact.queryKey(/*id*/1, (err, data) => { if (err) { console.log(`queryKey callback: err->${JSON.stringify(err)}`); @@ -1373,7 +1373,7 @@ Queries the key of a contact based on the specified contact ID and application. **Example** - ``` + ```js contact.queryKey(id, { holderId:1 }, (err, data) => { @@ -1409,7 +1409,7 @@ Queries the key of a contact based on the specified contact ID and application. **Example** - ``` + ```js let promise = contact.queryKey(id, { holderId: 0 }); @@ -1462,7 +1462,7 @@ Defines a contact. Create contact data in JSON format: -``` +```js let myContact = { phoneNumbers: [{ phoneNumber: "138xxxxxxxx" @@ -1480,7 +1480,7 @@ let myContact = { Or, create data by configuring a new Contact object. -``` +```js let myContact = new contact.Contact(); let name = new contact.Name(); name.fullName = "fullName"; @@ -1508,7 +1508,7 @@ If **null** is passed, all attributes are queried by default. Create contact data in JSON format: -``` +```js let contactAttributes = { attributes: [ contact.Attribute.ATTR_EMAIL, @@ -1521,7 +1521,7 @@ let contactAttributes = { Or, create data by configuring a **ContactAttributes** object. -``` +```js let contactAttributes = new contact.ContactAttributes(); contactAttributes.attributes = ["ATTR_EMAIL"]; ``` @@ -1555,7 +1555,7 @@ Enumerates contact attributes. Create contact data in JSON format: -``` +```js let attributes = [contact.Attribute.ATTR_EMAIL, contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_PHONE]; ``` @@ -1591,7 +1591,7 @@ Defines a contact's email. Create contact data in JSON format: -``` +```js let email = { email: "xxx@email.com", displayName: "displayName" @@ -1601,7 +1601,7 @@ let email = { Or, create data by configuring an **Email** object. -``` +```js let email = new contact.Email(); email.email = "xxx@email.com"; ``` @@ -1624,7 +1624,7 @@ Defines an application that creates the contact. Create contact data in JSON format: -``` +```js let holder = { holderId: 0 }; @@ -1632,7 +1632,7 @@ let holder = { Or, create data by configuring a **Holder** object. -``` +```js let holder = new contact.Holder(); holder.holderId = 0; ``` @@ -1668,7 +1668,7 @@ Defines a contact's event. Create contact data in JSON format: -``` +```js let event = { eventDate: "xxxxxx" }; @@ -1676,7 +1676,7 @@ let event = { Or, create data by configuring an **Event** object. -``` +```js let event = new contact.Event(); event.eventDate = "xxxxxx"; ``` @@ -1698,7 +1698,7 @@ Defines a contact group. Create contact data in JSON format: -``` +```js let group = { groupId: 1, title: "title" @@ -1707,7 +1707,7 @@ let group = { Or, create data by configuring a **Group** object. -``` +```js let group = new contact.Group(); group.title = "title"; ``` @@ -1747,7 +1747,7 @@ Enumerates IM addresses. Create contact data in JSON format: -``` +```js let imAddress = { imAddress: "imAddress", labelName: "labelName" @@ -1757,7 +1757,7 @@ let imAddress = { Or, create data by configuring an **ImAddress** object. -``` +```js let imAddress = new contact.ImAddress(); imAddress.imAddress = "imAddress"; ``` @@ -1786,7 +1786,7 @@ Defines a contact's name. Create contact data in JSON format: -``` +```js let name = { familyName: "familyName", fullName: "fullName" @@ -1795,7 +1795,7 @@ let name = { Or, create data by configuring a **Name** object. -``` +```js let name = new contact.Name(); name.familyName = "familyName"; name.fullName = "fullName"; @@ -1817,7 +1817,7 @@ Defines a contact's nickname. Create contact data in JSON format: -``` +```js let nickName = { nickName: "nickName" }; @@ -1825,7 +1825,7 @@ let nickName = { Or, create data by configuring a **NickName** object. -``` +```js let nickName = new contact.NickName(); nickName.nickName = "nickName"; ``` @@ -1846,7 +1846,7 @@ Defines a contact's note. Create contact data in JSON format: -``` +```js let note = { noteContent: "noteContent" }; @@ -1854,7 +1854,7 @@ let note = { Or, create data by configuring a **Note** object. -``` +```js let note = new contact.Note(); note.noteContent = "noteContent"; ``` @@ -1876,7 +1876,7 @@ Defines a contact's organization. Create contact data in JSON format: -``` +```js let organization = { name: "name", title: "title" @@ -1885,7 +1885,7 @@ let organization = { Or, create data by configuring an **Organization** object. -``` +```js let organization = new contact.Organization(); organization.name = "name"; organization.title = "title"; @@ -1939,7 +1939,7 @@ Defines a contact's phone number. Create contact data in JSON format: -``` +```js let phoneNumber = { phoneNumber: "138xxxxxxxx", labelId: contact.PhoneNumber.NUM_HOME @@ -1948,7 +1948,7 @@ let phoneNumber = { Or, create data by configuring a new **PhoneNumber** object. -``` +```js let phoneNumber = new contact.PhoneNumber(); phoneNumber.phoneNumber = "138xxxxxxxx"; ``` @@ -1969,7 +1969,7 @@ Defines a contact's portrait. Create contact data in JSON format: -``` +```js let portrait = { uri: "uri" }; @@ -1977,7 +1977,7 @@ let portrait = { Or, create data by configuring a new **Portrait** object. -``` +```js let portrait = new contact.Portrait(); portrait.uri = "uri"; ``` @@ -2020,7 +2020,7 @@ Defines a contact's postal address. Create contact data in JSON format: -``` +```js let postalAddress = { city: "city" }; @@ -2028,7 +2028,7 @@ let postalAddress = { Or, create data by configuring a new **PostalAddress** object. -``` +```js let postalAddress = new contact.PostalAddress(); postalAddress.city = "city"; ``` @@ -2075,7 +2075,7 @@ Defines a contact's relationship. Create contact data in JSON format: -``` +```js let relation = { relationName: "relationName", labelId: contact.Relation.RELATION_ASSISTANT @@ -2084,7 +2084,7 @@ let relation = { Or, create data by configuring a new **Relation** object. -``` +```js let relation = new contact.Relation(); relation.relationName = "relationName"; relation.labelId = contact.Relation.RELATION_ASSISTANT; @@ -2121,7 +2121,7 @@ Defines a contact's SIP address. Create contact data in JSON format: -``` +```js var sipAddress = { sipAddress: "sipAddress" }; @@ -2129,7 +2129,7 @@ var sipAddress = { Or, create data by configuring a new **SipAddress** object. -``` +```js let sipAddress = new contact.SipAddress(); sipAddress.sipAddress = "sipAddress"; ``` @@ -2150,7 +2150,7 @@ Defines a contact's website. Create contact data in JSON format: -``` +```js let website = { website: "website" }; @@ -2158,7 +2158,7 @@ let website = { Or, create data by configuring a new **Website** object. -``` +```js let website = new contact.Website(); website.website = "website"; ``` diff --git a/en/application-dev/reference/apis/js-apis-http.md b/en/application-dev/reference/apis/js-apis-http.md index c4c8d11faf..f1ef654168 100644 --- a/en/application-dev/reference/apis/js-apis-http.md +++ b/en/application-dev/reference/apis/js-apis-http.md @@ -7,13 +7,13 @@ ## Modules to Import -``` +```js import http from '@ohos.net.http'; ``` ## Example -``` +```js import http from '@ohos.net.http'; // Each HttpRequest corresponds to an HttpRequestTask object and cannot be reused. @@ -71,7 +71,7 @@ Creates an HTTP request. You can use this API to initiate or destroy an HTTP req **Example** -``` +```js import http from '@ohos.net.http'; let httpRequest = http.createHttp(); ``` @@ -100,7 +100,7 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback **Example** -``` +```js httpRequest.request("EXAMPLE_URL", (err, data) => { if (!err) { console.info('Result:' + data.result); @@ -133,7 +133,7 @@ Initiates an HTTP request containing specified options to a given URL. This API **Example** -``` +```js httpRequest.request("EXAMPLE_URL", { method: http.RequestMethod.GET, @@ -183,7 +183,7 @@ Initiates an HTTP request to a given URL. This API uses a promise to return the **Example** -``` +```js let promise = httpRequest.request("EXAMPLE_URL", { method: http.RequestMethod.GET, connectTimeout: 60000, @@ -214,7 +214,7 @@ Destroys an HTTP request. **Example** -``` +```js httpRequest.destroy(); ``` @@ -239,7 +239,7 @@ Registers an observer for HTTP Response Header events. **Example** -``` +```js httpRequest.on('headerReceive', (err, data) => { if (!err) { console.info('header: ' + JSON.stringify(data)); @@ -273,7 +273,7 @@ Unregisters the observer for HTTP Response Header events. **Example** -``` +```js httpRequest.off('headerReceive'); ``` @@ -294,7 +294,7 @@ Registers an observer for HTTP Response Header events. **Example** -``` +```js httpRequest.on('headersReceive', (header) => { console.info('header: ' + JSON.stringify(header)); }); @@ -322,7 +322,7 @@ Unregisters the observer for HTTP Response Header events. **Example** -``` +```js httpRequest.off('headersReceive'); ``` @@ -343,7 +343,7 @@ Registers a one-time observer for HTTP Response Header events. Once triggered, t **Example** -``` +```js httpRequest.once('headersReceive', (header) => { console.info('header: ' + JSON.stringify(header)); }); diff --git a/en/application-dev/reference/apis/js-apis-net-connection.md b/en/application-dev/reference/apis/js-apis-net-connection.md index bd4404ebc0..6e1eab82db 100644 --- a/en/application-dev/reference/apis/js-apis-net-connection.md +++ b/en/application-dev/reference/apis/js-apis-net-connection.md @@ -7,7 +7,7 @@ ## Modules to Import -```javascript +```js import connection from '@ohos.net.connection' ``` @@ -29,7 +29,7 @@ Obtains the default active data network. This API uses an asynchronous callback **Example** -```javascript +```js connection.getDefaultNet(function (error, netHandle) { console.log(JSON.stringify(error)) console.log(JSON.stringify(netHandle)) @@ -54,7 +54,7 @@ Obtains the default active data network. This API uses a promise to return the r **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { console.log(JSON.stringify(netHandle)) }) @@ -76,7 +76,7 @@ Checks whether the default data network is activated. This API uses an asynchron **Example** -```javascript +```js connection.hasDefaultNet(function (error, has) { console.log(JSON.stringify(error)) console.log(has) @@ -99,7 +99,7 @@ Checks whether the default data network is activated. This API uses a promise to **Example** -```javascript +```js connection.hasDefaultNet().then(function (has) { console.log(has) }) @@ -122,7 +122,7 @@ Obtains the list of all active data networks. This API uses an asynchronous call **Example** -``` +```js connection.getAllNets(function (error, nets) { console.log(JSON.stringify(error)) console.log(JSON.stringify(nets)) @@ -147,7 +147,7 @@ Obtains the list of all active data networks. This API uses a promise to return **Example** -``` +```js connection.getAllNets().then(function (nets) { console.log(JSON.stringify(nets)) }); @@ -172,7 +172,7 @@ Obtains connection properties of the network corresponding to given network hand **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { connection.getConnectionProperties(netHandle, function (error, info) { console.log(JSON.stringify(error)) @@ -205,7 +205,7 @@ Obtains connection properties of the network corresponding to **netHandle**. Thi **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { connection.getConnectionProperties(netHandle).then(function (info) { console.log(JSON.stringify(info)) @@ -232,7 +232,7 @@ Obtains capability information of the network corresponding to **netHandle**. Th **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { connection.getNetCapabilities(netHandle, function (error, info) { console.log(JSON.stringify(error)) @@ -265,7 +265,7 @@ Obtains capability information of the network corresponding to **netHandle**. Th **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { connection.getNetCapabilities(netHandle).then(function (info) { console.log(JSON.stringify(info)) @@ -291,7 +291,7 @@ Reports connection of the data network. This API uses an asynchronous callback t **Example** -``` +```js connection.getDefaultNet().then(function (netHandle) { connection.reportNetConnected(netHandle, function (error) { console.log(JSON.stringify(error)) @@ -322,7 +322,7 @@ Reports connection of the data network. This API uses a promise to return the re **Example** -``` +```js connection.getDefaultNet().then(function (netHandle) { connection.reportNetConnected(netHandle).then(function () { console.log(`report success`) @@ -349,7 +349,7 @@ Reports disconnection of the data network. This API uses an asynchronous callbac **Example** -``` +```js connection.getDefaultNet().then(function (netHandle) { connection.reportNetDisconnected(netHandle, function (error) { console.log(JSON.stringify(error)) @@ -380,7 +380,7 @@ Reports disconnection of the data network. This API uses a promise to return the **Example** -``` +```js connection.getDefaultNet().then(function (netHandle) { connection.reportNetDisconnected(netHandle).then(function () { console.log(`report success`) @@ -407,7 +407,7 @@ Resolves the host name by using the default network to obtain all IP addresses. **Example** -``` +```js let host = "xxxx"; connection.getAddressesByName(host, function (error, addresses) { console.log(JSON.stringify(error)) @@ -439,7 +439,7 @@ Resolves the host name by using the default network to obtain all IP addresses. **Example** -``` +```js let host = "xxxx"; connection.getAddressesByName(host).then(function (addresses) { console.log(JSON.stringify(addresses)) @@ -469,7 +469,7 @@ Obtains the handle of the network specified by **netSpecifier**. **Example** -```javascript +```js // Default network let netConnection = connection.createNetConnection() @@ -502,7 +502,7 @@ Registers a listener for **netAvailable** events. **Example** -```javascript +```js netConnection.on('netAvailable', function (data) { console.log(JSON.stringify(data)) }) @@ -525,7 +525,7 @@ Registers a listener for **netCapabilitiesChange** events. **Example** -```javascript +```js netConnection.on('netCapabilitiesChange', function (data) { console.log(JSON.stringify(data)) }) @@ -548,7 +548,7 @@ Registers a listener for **netConnectionPropertiesChange** events. **Example** -```javascript +```js netConnection.on('netConnectionPropertiesChange', function (data) { console.log(JSON.stringify(data)) }) @@ -571,7 +571,7 @@ Registers a listener for **netBlockStatusChange** events. **Example** -```javascript +```js netConnection.on('netBlockStatusChange', function (data) { console.log(JSON.stringify(data)) }) @@ -594,7 +594,7 @@ Registers a listener for **netLost** events. **Example** -```javascript +```js let netConnection1 = connection.createNetConnection() netConnection1.on('netLost', function (data) { console.log(JSON.stringify(data)) @@ -618,7 +618,7 @@ Registers a listener for **netUnavailable** events. **Example** -```javascript +```js netConnection.on('netUnavailable', function (data) { console.log(JSON.stringify(data)) }) @@ -642,7 +642,7 @@ Registers a listener for network status changes. **Example** -```javascript +```js netConnection.register(function (error) { console.log(JSON.stringify(error)) }) @@ -664,7 +664,7 @@ Unregisters the listener for network status changes. **Example** -```javascript +```js netConnection.unregister(function (error) { console.log(JSON.stringify(error)) }) @@ -703,7 +703,7 @@ Resolves the host name by using the corresponding network to obtain all IP addre **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { let host = "xxxx"; netHandle.getAddressesByName(host, function (error, addresses) { @@ -737,7 +737,7 @@ Resolves the host name by using the corresponding network to obtain all IP addre **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { let host = "xxxx"; netHandle.getAddressesByName(host).then(function (addresses) { @@ -765,7 +765,7 @@ Resolves the host name by using the corresponding network to obtain the first IP **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { let host = "xxxx"; netHandle.getAddressByName(host, function (error, address) { @@ -799,7 +799,7 @@ Resolves the host name by using the corresponding network to obtain the first IP **Example** -```javascript +```js connection.getDefaultNet().then(function (netHandle) { let host = "xxxx"; netHandle.getAddressByName(host).then(function (address) { diff --git a/en/application-dev/reference/apis/js-apis-observer.md b/en/application-dev/reference/apis/js-apis-observer.md index 29d9e85a23..b68d1dc35b 100644 --- a/en/application-dev/reference/apis/js-apis-observer.md +++ b/en/application-dev/reference/apis/js-apis-observer.md @@ -7,7 +7,7 @@ ## Modules to Import -``` +```js import observer from '@ohos.telephony.observer' ``` @@ -30,7 +30,7 @@ Registers an observer for network status change events. This API uses an asynchr **Example** -``` +```js observer.on('networkStateChange', data =>{ console.log("on networkStateChange, data:" + JSON.stringify(data)); }); @@ -57,7 +57,7 @@ Registers an observer for network status change events of the SIM card in the sp **Example** -``` +```js observer.on('networkStateChange', {slotId: 0}, data =>{ console.log("on networkStateChange, data:" + JSON.stringify(data)); }); @@ -87,7 +87,7 @@ Unregisters the observer for network status change events. This API uses an asyn **Example** -``` +```js let callback = data => { console.log("on networkStateChange, data:" + JSON.stringify(data)); } @@ -114,7 +114,7 @@ Registers an observer for signal status change events. This API uses an asynchro **Example** -``` +```js observer.on('signalInfoChange', data =>{ console.log("on signalInfoChange, data:" + JSON.stringify(data)); }); @@ -139,7 +139,7 @@ Registers an observer for signal status change events of the SIM card in the spe **Example** -``` +```js observer.on('signalInfoChange', {slotId: 0}, data =>{ console.log("on signalInfoChange, data:" + JSON.stringify(data)); }); @@ -167,7 +167,7 @@ Unregisters the observer for signal status change events. This API uses an async **Example** -``` +```js let callback = data => { console.log("on signalInfoChange, data:" + JSON.stringify(data)); } @@ -197,7 +197,7 @@ Registers an observer for call status change events. This API uses an asynchrono **Example** -``` +```js observer.on('callStateChange', value =>{ console.log("on callStateChange, state:" + value.state + ", number:" + value.number); }); @@ -224,7 +224,7 @@ Registers an observer for call status change events. This API uses an asynchrono **Example** -``` +```js observer.on('callStateChange', {slotId: 0}, value =>{ console.log("on callStateChange, state:" + value.state + ", number:" + value.number); }); @@ -254,7 +254,7 @@ Unregisters the observer for call status change events. This API uses an asynchr **Example** -``` +```js let callback = value => { console.log("on callStateChange, state:" + value.state + ", number:" + value.number); } @@ -282,7 +282,7 @@ Registers an observer for connection status change events of the cellular data l **Example** -``` +```js observer.on('cellularDataConnectionStateChange', value =>{ console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network); }); @@ -307,7 +307,7 @@ Registers an observer for connection status change events of the cellular data l **Example** -``` +```js observer.on('cellularDataConnectionStateChange', {slotId: 0}, value =>{ console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network); }); @@ -335,7 +335,7 @@ Unregisters the observer for connection status change events of the cellular dat **Example** -``` +```js let callback = value => { console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network); } @@ -363,7 +363,7 @@ Registers an observer for the uplink and downlink data flow status change events **Example** -``` +```js observer.on('cellularDataFlowChange', data =>{ console.log("on networkStateChange, data:" + JSON.stringify(data)); }); @@ -388,7 +388,7 @@ Registers an observer for the uplink and downlink data flow status change events **Example** -``` +```js observer.on('cellularDataFlowChange', {slotId: 0}, data =>{ console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); }); @@ -416,7 +416,7 @@ Unregisters the observer for the uplink and downlink data flow status change eve **Example** -``` +```js let callback = data => { console.log("on cellularDataFlowChange, data:" + JSON.stringify(data)); } @@ -444,7 +444,7 @@ Registers an observer for SIM card status change events. This API uses an asynch **Example** -``` +```js observer.on('simStateChange', data =>{ console.log("on simStateChange, data:" + JSON.stringify(data)); }); @@ -469,7 +469,7 @@ Registers an observer for status change events of the SIM card in the specified **Example** -``` +```js observer.on('simStateChange', {slotId: 0}, data =>{ console.log("on simStateChange, data:" + JSON.stringify(data)); }); @@ -497,7 +497,7 @@ Unregisters the observer for SIM card status change events. This API uses an asy **Example** -``` +```js let callback = data => { console.log("on simStateChange, data:" + JSON.stringify(data)); } diff --git a/en/application-dev/reference/apis/js-apis-radio.md b/en/application-dev/reference/apis/js-apis-radio.md index 468091db60..4df1f4e33d 100644 --- a/en/application-dev/reference/apis/js-apis-radio.md +++ b/en/application-dev/reference/apis/js-apis-radio.md @@ -7,7 +7,7 @@ ## Modules to Import -``` +```js import radio from '@ohos.telephony.radio' ``` @@ -30,7 +30,7 @@ Obtains the radio access technology (RAT) used by the CS and PS domains. This AP **Example** -``` +```js let slotId = 0; radio.getRadioTech(slotId, (err, data) =>{ console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -62,7 +62,7 @@ Obtains the RAT used by the CS and PS domains. This API uses a promise to return **Example** -``` +```js let slotId = 0; let promise = radio.getRadioTech(slotId); promise.then(data => { @@ -91,7 +91,7 @@ Obtains the network status. This API uses an asynchronous callback to return the **Example** -``` +```js radio.getNetworkState((err, data) =>{ console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -117,7 +117,7 @@ Obtains the network status. This API uses an asynchronous callback to return the **Example** -``` +```js let slotId = 0; radio.getNetworkState(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -149,7 +149,7 @@ Obtains the network status of the SIM card in the specified slot. This API uses **Example** -``` +```js let slotId = 0; let promise = radio.getNetworkState(slotId); promise.then(data => { @@ -177,7 +177,7 @@ Obtains the network selection mode of the SIM card in the specified slot. This A **Example** -``` +```js let slotId = 0; radio.getNetworkSelectionMode(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -207,7 +207,7 @@ Obtains the network selection mode of the SIM card in the specified slot. This A **Example** -``` +```js let slotId = 0; let promise = radio.getNetworkSelectionMode(slotId); promise.then(data => { @@ -235,7 +235,7 @@ Obtains the ISO country code of the network with which the SIM card in the speci **Example** -``` +```js let slotId = 0; radio.getISOCountryCodeForNetwork(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -265,7 +265,7 @@ Obtains the ISO country code of the network with which the SIM card in the speci **Example** -``` +```js let slotId = 0; let promise = radio.getISOCountryCodeForNetwork(slotId); promise.then(data => { @@ -292,7 +292,7 @@ Obtains the ID of the slot in which the primary card is located. This API uses a **Example** -``` +```js radio.getPrimarySlotId((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -315,7 +315,7 @@ Obtains the ID of the slot in which the primary card is located. This API uses a **Example** -``` +```js let promise = radio.getPrimarySlotId(); promise.then(data => { console.log(`getPrimarySlotId success, promise: data->${JSON.stringify(data)}`); @@ -342,7 +342,7 @@ Obtains a list of signal strengths of the network with which the SIM card in the **Example** -``` +```js let slotId = 0; radio.getSignalInformation(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -372,7 +372,7 @@ Obtains a list of signal strengths of the network with which the SIM card in the **Example** -``` +```js let slotId = 0; let promise = radio.getSignalInformation(slotId); promise.then(data => { @@ -405,7 +405,7 @@ Checks whether the current device supports 5G \(NR\). **Example** -``` +```js let slotId = 0; let result = radio.isNrSupported(slotId); console.log(result); @@ -430,7 +430,7 @@ Checks whether the radio service is enabled on the primary SIM card. This API us **Example** -``` +```js radio.isRadioOn((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -456,7 +456,7 @@ Checks whether the radio service is enabled on the SIM card in the specified slo **Example** -``` +```js let slotId = 0; radio.isRadioOn(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -488,7 +488,7 @@ Checks whether the radio service is enabled. This API uses a promise to return t **Example** -``` +```js let slotId = 0; let promise = radio.isRadioOn(slotId); promise.then(data => { @@ -516,7 +516,7 @@ Obtains the carrier name. This API uses an asynchronous callback to return the r **Example** -``` +```js let slotId = 0; radio.getOperatorName(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -546,7 +546,7 @@ Obtains the carrier name. This API uses a promise to return the result. **Example** -``` +```js let slotId = 0; let promise = radio.getOperatorName(slotId); promise.then(data => { diff --git a/en/application-dev/reference/apis/js-apis-sim.md b/en/application-dev/reference/apis/js-apis-sim.md index 85e895952f..f1f20e8d81 100644 --- a/en/application-dev/reference/apis/js-apis-sim.md +++ b/en/application-dev/reference/apis/js-apis-sim.md @@ -7,7 +7,7 @@ ## Modules to Import -``` +```js import sim from '@ohos.telephony.sim'; ``` @@ -28,7 +28,7 @@ Checks whether the SIM card in the specified slot is activated. This API uses an **Example** -``` +```js sim.isSimActive(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -57,7 +57,7 @@ Checks whether the SIM card in the specified slot is activated. This API uses a **Example** -``` +```js let promise = sim.isSimActive(0); promise.then(data => { console.log(`isSimActive success, promise: data->${JSON.stringify(data)}`); @@ -83,7 +83,7 @@ Obtains the default slot ID of the SIM card that provides voice services. This A **Example** -``` +```js sim.getDefaultVoiceSlotId((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -106,7 +106,7 @@ Obtains the default slot ID of the SIM card that provides voice services. This A **Example** -``` +```js let promise = sim.getDefaultVoiceSlotId(); promise.then(data => { console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`); @@ -132,7 +132,7 @@ Checks whether the application (caller) has been granted the operator permission **Example** -``` +```js sim.hasOperatorPrivileges(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -160,7 +160,7 @@ Checks whether the application (caller) has been granted the operator permission **Example** -``` +```js let promise = sim.hasOperatorPrivileges(0); promise.then(data => { console.log(`hasOperatorPrivileges success, promise: data->${JSON.stringify(data)}`); @@ -186,7 +186,7 @@ Obtains the ISO country code of the SIM card in the specified slot. This API use **Example** -``` +```js sim.getISOCountryCodeForSim(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -215,7 +215,7 @@ Obtains the ISO country code of the SIM card in the specified slot. This API use **Example** -``` +```js let promise = sim.getISOCountryCodeForSim(0); promise.then(data => { console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`); @@ -242,7 +242,7 @@ Obtains the public land mobile network (PLMN) ID of the SIM card in the specifie **Example** -``` +```js sim.getSimOperatorNumeric(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -271,7 +271,7 @@ Obtains the PLMN ID of the SIM card in the specified slot. This API uses a promi **Example** -``` +```js let promise = sim.getSimOperatorNumeric(0); promise.then(data => { console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`); @@ -298,7 +298,7 @@ Obtains the service provider name (SPN) of the SIM card in the specified slot. T **Example** -``` +```js sim.getSimSpn(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -327,7 +327,7 @@ Obtains the SPN of the SIM card in the specified slot. This API uses a promise t **Example** -``` +```js let promise = sim.getSimSpn(0); promise.then(data => { console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`); @@ -354,7 +354,7 @@ Obtains the status of the SIM card in the specified slot. This API uses an async **Example** -``` +```js sim.getSimState(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -383,7 +383,7 @@ Obtains the status of the SIM card in the specified slot. This API uses a promis **Example** -``` +```js let promise = sim.getSimState(0); promise.then(data => { console.log(`getSimState success, promise: data->${JSON.stringify(data)}`); @@ -409,7 +409,7 @@ Obtains the type of the SIM card in the specified slot. This API uses an asynchr **Example** -``` +```js sim.getCardType(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -438,7 +438,7 @@ Obtains the type of the SIM card in the specified slot. This API uses a promise **Example** -``` +```js let promise = sim.getCardType(0); promise.then(data => { console.log(`getCardType success, promise: data->${JSON.stringify(data)}`); @@ -465,7 +465,7 @@ Checks whether the SIM card in the specified slot is installed. This API uses an **Example** -``` +```js sim.hasSimCard(0, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -494,7 +494,7 @@ Checks whether the SIM card in the specified slot is installed. This API uses a **Example** -``` +```js let promise = sim.hasSimCard(0); promise.then(data => { console.log(`hasSimCard success, promise: data->${JSON.stringify(data)}`); @@ -520,7 +520,7 @@ Obtains the number of card slots. **Example** -``` +```js console.log(sim.getMaxSimCount()) ``` diff --git a/en/application-dev/reference/apis/js-apis-sms.md b/en/application-dev/reference/apis/js-apis-sms.md index e874588b5e..85e8f3f411 100644 --- a/en/application-dev/reference/apis/js-apis-sms.md +++ b/en/application-dev/reference/apis/js-apis-sms.md @@ -6,7 +6,7 @@ ## Modules to Import -``` +```js import sms from '@ohos.telephony.sms'; ``` @@ -28,7 +28,7 @@ Creates an SMS message instance based on the protocol data unit (PDU) and the sp **Example** -``` +```js const specification = '3gpp'; // Display PDUs using numbers in an array, for example, [0x08, 0x91, ...]. const pdu = [0x08, 0x91]; @@ -61,7 +61,7 @@ Creates an SMS message instance based on the PDU and the specified SMS protocol. **Example** -``` +```js const specification = '3gpp'; // Display PDUs using numbers in an array, for example, [0x08, 0x91, ...]. const pdu = [0x08, 0x91]; @@ -91,7 +91,7 @@ Sends an SMS message. **Example** -``` +```js let sendCallback = function (err, data) { console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); } @@ -124,7 +124,7 @@ Obtains the default slot of the SIM card used to send SMS messages. This API use **Example** -``` +```js sms.getDefaultSmsSlotId((err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); }); @@ -147,7 +147,7 @@ Obtains the default slot of the SIM card used to send SMS messages. This API use **Example** -``` +```js let promise = sms.getDefaultSmsSlotId(); promise.then(data => { console.log(`getDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`); @@ -179,7 +179,7 @@ This is a system API and cannot be called by third-party applications. **Example** -``` +```js let slotId = 0; let smscAddr = '+861xxxxxxxxxx'; sms.setSmscAddr(slotId, smscAddr, (err,data) => { @@ -215,7 +215,7 @@ This is a system API and cannot be called by third-party applications. **Example** -``` +```js let slotId = 0; let smscAddr = '+861xxxxxxxxxx'; let promise = sms.setSmscAddr(slotId, smscAddr); @@ -248,7 +248,7 @@ This is a system API and cannot be called by third-party applications. **Example** -``` +```js let slotId = 0; sms.getSmscAddr(slotId, (err, data) => { console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); @@ -282,7 +282,7 @@ This is a system API and cannot be called by third-party applications. **Example** -``` +```js let slotId = 0; let promise = sms.getSmscAddr(slotId); promise.then(data => { @@ -306,7 +306,7 @@ Checks whether the current device can send and receive SMS messages. This API wo | ------- | ------------------------------------------------------------ | | boolean | - **true**: The device can send and receive SMS messages.
- **false**: The device cannot send or receive SMS messages.| -``` +```js let result = sms.hasSmsCapability(); console.log(`hasSmsCapability: ${JSON.stringify(result)}`); ``` diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md index dcaf0416c8..2c83bd2e48 100644 --- a/en/application-dev/reference/apis/js-apis-socket.md +++ b/en/application-dev/reference/apis/js-apis-socket.md @@ -7,7 +7,7 @@ ## Modules to Import -``` +```js import socket from '@ohos.net.socket'; ``` @@ -28,7 +28,7 @@ Creates a **UDPSocket** object. **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); ``` @@ -56,7 +56,7 @@ Binds the IP address and port number. The port number can be specified or random **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { @@ -93,7 +93,7 @@ Binds the IP address and port number. The port number can be specified or random **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); let promise = udp.bind({address: '192.168.xx.xxx', port: 8080, family: 1}); promise .then(() => { @@ -123,7 +123,7 @@ Sends data over a UDPSocket connection. This API uses an asynchronous callback t **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.send({ data:'Hello, server!', @@ -166,7 +166,7 @@ Sends data over a UDPSocket connection. This API uses a promise to return the re **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); let promise = udp.send({ data:'Hello, server!', @@ -202,7 +202,7 @@ Closes a UDPSocket connection. This API uses an asynchronous callback to return **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.close(err => { if (err) { @@ -232,7 +232,7 @@ Closes a UDPSocket connection. This API uses a promise to return the result. **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); let promise = udp.close(); promise.then(() => { @@ -264,7 +264,7 @@ Obtains the status of the UDPSocket connection. This API uses an asynchronous ca **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { @@ -304,7 +304,7 @@ Obtains the status of the UDPSocket connection. This API uses a promise to retur **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { @@ -345,7 +345,7 @@ Sets other properties of the UDPSocket connection. This API uses an asynchronous **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.bind({address:'192.168.xx.xxx', port:xxxx, family:1}, err=> { if (err) { @@ -397,7 +397,7 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); let promise = udp.bind({address:'192.168.xx.xxx', port:xxxx, family:1}); promise.then(() => { @@ -437,7 +437,7 @@ Enables listening for message receiving events of the UDPSocket connection. This **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.on('message', value => { console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); @@ -465,7 +465,7 @@ Disables listening for message receiving events of the UDPSocket connection. Thi **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); let callback = value =>{ console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); @@ -494,7 +494,7 @@ Enables listening for data packet message events or close events of the UDPSocke **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.on('listening', () => { console.log("on listening success"); @@ -525,7 +525,7 @@ Disables listening for data packet message events or close events of the UDPSock **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); let callback1 = () =>{ console.log("on listening, success"); @@ -562,7 +562,7 @@ Enables listening for error events of the UDPSocket connection. This API uses an **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); udp.on('error', err => { console.log("on error, err:" + JSON.stringify(err)) @@ -590,7 +590,7 @@ Disables listening for error events of the UDPSocket connection. This API uses a **Example** -``` +```js let udp = socket.constructUDPSocketInstance(); let callback = err =>{ console.log("on error, err:" + JSON.stringify(err)); @@ -680,7 +680,7 @@ Creates a **TCPSocket** object. **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); ``` @@ -709,7 +709,7 @@ Binds the IP address and port number. The port number can be specified or random **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { @@ -745,7 +745,7 @@ Binds the IP address and port number. The port number can be specified or random **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); promise.then(() => { @@ -775,7 +775,7 @@ Sets up a connection to the specified IP address and port number. This API uses **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}, err => { if (err) { @@ -811,7 +811,7 @@ Sets up a connection to the specified IP address and port number. This API uses **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise.then(() => { @@ -844,7 +844,7 @@ Sends data over a TCPSocket connection. This API uses an asynchronous callback t **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise.then(() => { @@ -891,7 +891,7 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise1 = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise1.then(() => { @@ -929,7 +929,7 @@ Closes a TCPSocket connection. This API uses an asynchronous callback to return **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); tcp.close(err => { if (err) { @@ -959,7 +959,7 @@ Closes a TCPSocket connection. This API uses a promise to return the result. **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.close(); promise.then(() => { @@ -991,7 +991,7 @@ Obtains the remote address of a TCPSocket connection. This API uses an asynchron **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise.then(() => { @@ -1030,7 +1030,7 @@ Obtains the remote address of a TCPSocket connection. This API uses a promise to **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise1 = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise1.then(() => { @@ -1069,7 +1069,7 @@ Obtains the status of the TCPSocket connection. This API uses an asynchronous ca **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise.then(() => { @@ -1109,7 +1109,7 @@ Obtains the status of the TCPSocket connection. This API uses a promise to retur **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise.then(() => { @@ -1148,7 +1148,7 @@ Sets other properties of the TCPSocket connection. This API uses an asynchronous **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise.then(() => { @@ -1203,7 +1203,7 @@ Sets other properties of the TCPSocket connection. This API uses a promise to re **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); promise.then(() => { @@ -1246,7 +1246,7 @@ Enables listening for message receiving events of the TCPSocket connection. This **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); tcp.on('message', value => { console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo) @@ -1274,7 +1274,7 @@ Disables listening for message receiving events of the TCPSocket connection. Thi **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let callback = value =>{ console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); @@ -1304,7 +1304,7 @@ Enables listening for connection or close events of the TCPSocket connection. Th **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); tcp.on('connect', () => { console.log("on connect success") @@ -1335,7 +1335,7 @@ Disables listening for connection or close events of the TCPSocket connection. T **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let callback1 = () =>{ console.log("on connect success"); @@ -1371,7 +1371,7 @@ Enables listening for error events of the TCPSocket connection. This API uses an **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); tcp.on('error', err => { console.log("on error, err:" + JSON.stringify(err)) @@ -1399,7 +1399,7 @@ Disables listening for error events of the TCPSocket connection. This API uses a **Example** -``` +```js let tcp = socket.constructTCPSocketInstance(); let callback = err =>{ console.log("on error, err:" + JSON.stringify(err)); diff --git a/en/application-dev/reference/apis/js-apis-webSocket.md b/en/application-dev/reference/apis/js-apis-webSocket.md index 1796e369ab..a1a24975f9 100644 --- a/en/application-dev/reference/apis/js-apis-webSocket.md +++ b/en/application-dev/reference/apis/js-apis-webSocket.md @@ -12,13 +12,13 @@ If an error occurs in any of the preceding processes, the client will receive a ## Modules to Import -``` +```js import webSocket from '@ohos.net.webSocket'; ``` ## Complete Example -``` +```js import webSocket from '@ohos.net.webSocket'; var defaultIpAddress = "ws://"; @@ -78,7 +78,7 @@ Creates a WebSocket connection. You can use this API to create or close a WebSoc **Example** -``` +```js let ws = webSocket.createWebSocket(); ``` @@ -107,7 +107,7 @@ Initiates a WebSocket request to establish a WebSocket connection to a given URL **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" ws.connect(url, (err, value) => { @@ -141,7 +141,7 @@ Initiates a WebSocket request carrying specified options to establish a WebSocke **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" ws.connect(url, { @@ -184,7 +184,7 @@ Initiates a WebSocket request carrying specified options to establish a WebSocke **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" let promise = ws.connect(url); @@ -215,7 +215,7 @@ Sends data through a WebSocket connection. This API uses an asynchronous callbac **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" ws.connect(url, (err, value) => { @@ -254,7 +254,7 @@ Sends data through a WebSocket connection. This API uses a promise to return the **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" ws.connect(url, (err, value) => { @@ -286,7 +286,7 @@ Closes a WebSocket connection. This API uses an asynchronous callback to return **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" ws.close((err, value) => { @@ -318,7 +318,7 @@ Closes a WebSocket connection carrying specified options such as **code** and ** **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" ws.close({ @@ -358,7 +358,7 @@ Closes a WebSocket connection carrying specified options such as **code** and ** **Example** -``` +```js let ws = webSocket.createWebSocket(); let url = "ws://" let promise = ws.close({ @@ -391,7 +391,7 @@ Enables listening for the **open** events of a WebSocket connection. This API us **Example** -``` +```js let ws = webSocket.createWebSocket(); ws.on('open', (err, value) => { console.log("on open, status:" + value.status + ", message:" + value.message); @@ -419,7 +419,7 @@ Disables listening for the **open** events of a WebSocket connection. This API u **Example** -``` +```js let ws = webSocket.createWebSocket(); let callback1 = (err, value) => { console.log("on open, status:" + value.status + ", message:" + value.message); @@ -451,7 +451,7 @@ Enables listening for the **message** events of a WebSocket connection. This API **Example** -``` +```js let ws = webSocket.createWebSocket(); ws.on('message', (err, value) => { console.log("on message, message:" + value); @@ -480,7 +480,7 @@ Disables listening for the **message** events of a WebSocket connection. This AP **Example** -``` +```js let ws = webSocket.createWebSocket(); ws.off('message'); ``` @@ -503,7 +503,7 @@ Enables listening for the **close** events of a WebSocket connection. This API u **Example** -``` +```js let ws = webSocket.createWebSocket(); ws.on('close', (err, value) => { console.log("on close, code is " + value.code + ", reason is " + value.reason); @@ -532,7 +532,7 @@ Disables listening for the **close** events of a WebSocket connection. This API **Example** -``` +```js let ws = webSocket.createWebSocket(); ws.off('close'); ``` @@ -556,7 +556,7 @@ Enables listening for the **error** events of a WebSocket connection. This API u **Example** -``` +```js let ws = webSocket.createWebSocket(); ws.on('error', (err) => { console.log("on error, error:" + JSON.stringify(err)) @@ -584,7 +584,7 @@ Disables listening for the **error** events of a WebSocket connection. This API **Example** -``` +```js let ws = webSocket.createWebSocket(); ws.off('error'); ``` -- GitLab