source
stringlengths
14
113
code
stringlengths
10
21.3k
application-dev\napi\use-napi-about-property.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; let obj = testNapi.napiSetNamedProperty('myProperty'); let objAsString = JSON.stringify(obj); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_named_property: %{public}s', objAsString);
application-dev\napi\use-napi-about-property.md
// index.d.ts export const napiGetNamedProperty: (obj: Object, key:string) => boolean | number | string | Object | void;
application-dev\napi\use-napi-about-property.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; interface NestedObj { nestedStr: string; nestedNum: number; } class Obj { str: string = ""; num: number = 0; bol: boolean = false; nestedObj: NestedObj = { nestedStr: "", nestedNum: 0 }; } let obj: Obj = {str: "bar", num: 42, bol: true, ...
application-dev\napi\use-napi-about-property.md
// index.d.ts export const napiHasNamedProperty: (obj: Object, key:string) => boolean | void;
application-dev\napi\use-napi-about-property.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; interface NestedObj { nestedStr: string; nestedNum: number; } class Obj { str: string = ""; num: number = 0; bol: boolean = false; nestedObj: NestedObj = { nestedStr: "", nestedNum: 0 }; } let obj: Obj = {str: "bar", num: 42, bol: true, ...
application-dev\napi\use-napi-about-property.md
// index.d.ts export class DefineMethodObj { defineMethodPropertiesExample: Function; } export class DefineStringObj { defineStringPropertiesExample: string; } export class DefineGetterSetterObj { getterCallback: Function; setterCallback: Function; } export const defineMethodProperties: () => DefineMethodObj; e...
application-dev\napi\use-napi-about-property.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; // Define a property of the method type. hilog.info(0x0000, 'testTag', 'Test Node-API define_method_properties:%{public}d', testNapi.defineMethodProperties() .defineMethodPropertiesExample()); // Define a property of the string type. hilog.info(0x00...
application-dev\napi\use-napi-about-property.md
// index.d.ts export const getAllPropertyNames : (obj: Object) => Array<string> | void;
application-dev\napi\use-napi-about-property.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; try { class Obj { data: number = 0 message: string = "" } let obj: Obj = { data: 0, message: "hello world"}; let propertyNames = testNapi.getAllPropertyNames(obj); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_na...
application-dev\napi\use-napi-about-string.md
// index.d.ts export const getValueStringUtf8: (param: string | number) => string | void;
application-dev\napi\use-napi-about-string.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; // Pass in a string and a number respectively. If the input is a string, the string will be returned. If the input is not a string, 'undefined' will be returned. hilog.info(0x0000, 'testTag','Test Node-API get_value_string_utf8_string %{public}s', tes...
application-dev\napi\use-napi-about-string.md
// index.d.ts export const createStringUtf8: () => string | void;
application-dev\napi\use-napi-about-string.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf8:%{public}s', testNapi.createStringUtf8());
application-dev\napi\use-napi-about-string.md
// index.d.ts export const getValueStringUtf16: (data: string) => string;
application-dev\napi\use-napi-about-string.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; let result = testNapi.getValueStringUtf16('hello,'); hilog.info(0x0000,'testTag','Node-API napi_get_value_string_utf16:%{public}s', result);
application-dev\napi\use-napi-about-string.md
// index.d.ts export const createStringUtf16: () => string | void;
application-dev\napi\use-napi-about-string.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf16:%{public}s ', testNapi.createStringUtf16());
application-dev\napi\use-napi-about-string.md
// index.d.ts export const getValueStringLatin1: (param: number | string) => string | void;
application-dev\napi\use-napi-about-string.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; // If non-character data is passed in, undefined will be returned. hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_not_string %{public}s', testNapi.getValueStringLatin1(10)); // The ISO-8859-1 encoding does not support Chinese cha...
application-dev\napi\use-napi-about-string.md
// index.d.ts export const createStringLatin1: () => string | void;
application-dev\napi\use-napi-about-string.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_latin1:%{public}s', testNapi.createStringLatin1());
application-dev\napi\use-napi-ark-runtime.md
// index.d.ts export const createArkRuntime: () => object;
application-dev\napi\use-napi-ark-runtime.md
// ObjectUtils.ets export function Logger() { console.log("print log"); } // Call ArkTS APIs. import testNapi from 'libentry.so'; testNapi.createArkRuntime();
application-dev\napi\use-napi-asynchronous-task.md
// Description of the interface in the .d.ts file. export const asyncWork: (data: number) => Promise<number>; // Call the API of ArkTS. nativeModule.asyncWork(1024).then((result) => { hilog.info(0x0000, 'XXX', 'result is %{public}d', result); });
application-dev\napi\use-napi-asynchronous-task.md
// Description of the interface in the .d.ts file. export const asyncWork: (arg1: number, arg2: number, callback: (result: number) => void) => void; // Call the API of ArkTS. let num1: number = 123; let num2: number = 456; nativeModule.asyncWork(num1, num2, (result) => { hilog.info(0x0000, 'XXX', '...
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const getValueUint32: <T>(data: T) => number | void;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; let value = testNapi.getValueUint32<number>(111111111111); let data = testNapi.getValueUint32<string>("sssss"); hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', value); // If "sssss" (a non-number) is passed in, undefined will be ...
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const getValueInt32: (value: number | string) => number | void;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; // If 'ss' (a non-number) is passed in, undefined will be returned. hilog.info(0x0000, 'Node-API', 'get_value_int32_not_number %{public}s', testNapi.getValueInt32('ss')); // If 100 (a number within the int32 value range) is passed in, the original nu...
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const getValueInt64: (value: number | string) => number | void;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; // If a number within the int64 value range is passed in, the original number will be returned. hilog.info(0x0000, 'Node-API', 'get_value_int64_number %{public}d', testNapi.getValueInt64(80)); // If 'sAs' (a non-number) is passed in, undefined will b...
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const getDouble: (value: number | string) => number | void;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; // If a number is passed in, the number will be returned. hilog.info(0x0000, 'Node-API', 'get_value_double_number %{public}d', testNapi.getDouble(80.885)); // If a non-number is passed in, undefined will be returned. hilog.info(0x0000, 'Node-API', 'ge...
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const createInt32: () => number;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_int32: ' + testNapi.createInt32());
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const createUInt32: () => number;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_uint32: ' + testNapi.createUInt32());
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const createInt64: () => number;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_int64: ' + testNapi.createInt64());
application-dev\napi\use-napi-basic-data-types.md
// index.d.ts export const createDouble: () => number;
application-dev\napi\use-napi-basic-data-types.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_double: ' + testNapi.createDouble());
application-dev\napi\use-napi-event-loop.md
// index.d.ts export const runEventLoop: (isDefault: boolean) => object;
application-dev\napi\use-napi-event-loop.md
// index.ets import testNapi from 'libentry.so' testNapi.runEventLoop(true);
application-dev\napi\use-napi-event-loop.md
// ets/pages/ObjectUtils.ets export function SetTimeout() : Promise<void> { return new Promise((resolve) => { setTimeout(() => { console.info('set timer delay 1s'); // attempt to stop the event loop at napi terminal resolve(); }, 1000) ...
application-dev\napi\use-napi-faqs.md
// Main thread Index.ets import worker, { MessageEvents } from '@ohos.worker'; const mWorker = new worker.ThreadWorker('../workers/Worker'); mWorker.onmessage = (e: MessageEvents) => { const action: string | undefined = e.data?.action; if (action === 'kill') { mWorker.terminate(); } } // The regis...
application-dev\napi\use-napi-faqs.md
// worker.ets import worker, { ThreadWorkerGlobalScope, MessageEvents, ErrorEvent } from '@ohos.worker'; import napiModule from 'libentry.so'; // libentry.so is the module name of the Node-API library. const workerPort: ThreadWorkerGlobalScope = worker.workerPort; workerPort.onmessage = (e: MessageEvents) => { co...
application-dev\napi\use-napi-life-cycle.md
// index.d.ts export const handleScopeTest: () => string; export const handleScope: () => string;
application-dev\napi\use-napi-life-cycle.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; try { hilog.info(0x0000, 'testTag', 'Test Node-API handleScopeTest: %{public}s', testNapi.handleScopeTest()); hilog.info(0x0000, 'testTag', 'Test Node-API handleScope: %{public}s', testNapi.handleScope()); } catch (error) { hilog.error(0x0000, '...
application-dev\napi\use-napi-life-cycle.md
// index.d.ts export const escapableHandleScopeTest: () => string;
application-dev\napi\use-napi-life-cycle.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; try { hilog.info(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest: %{public}s', testNapi.escapableHandleScopeTest()); } catch (error) { hilog.error(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest errorCode: %{public}s, errorMe...
application-dev\napi\use-napi-life-cycle.md
// index.d.ts export const createReference: () => Object | void; export const useReference: () => Object | void; export const deleteReference: () => string | void;
application-dev\napi\use-napi-life-cycle.md
import hilog from '@ohos.hilog'; import testNapi from 'libentry.so'; try { hilog.info(0x0000, 'testTag', 'Test Node-API createReference: %{public}s', JSON.stringify(testNapi.createReference())); hilog.info(0x0000, 'testTag', 'Test Node-API useReference: %{public}s', JSON.stringify(testNapi.useReference())); hilog...
application-dev\napi\use-napi-method-promise.md
// index.d.ts export const callArkTSAsync: (func: Function) => object;
application-dev\napi\use-napi-method-promise.md
// index.ets import testNapi from 'libentry.so' export function SetTimeout() : Promise<number> { return new Promise((resolve) => { setTimeout(() => { resolve(42); }, 1000) }) } testNapi.callArkTSAsync(SetTimeout);
application-dev\napi\use-napi-object-wrap.md
// index.d.ts export class MyObject { constructor(arg: number); plusOne: () => number; public get value(); public set value(newVal: number); }
application-dev\napi\use-napi-object-wrap.md
import hilog from '@ohos.hilog'; import { MyObject } from 'libentry.so'; let object : MyObject = new MyObject(0); object.value = 1023; hilog.info(0x0000, 'testTag', 'MyObject value after set: %{public}d', object.value); hilog.info(0x0000, 'testTag', 'MyObject plusOne: %{public}d', object.plusOne());
application-dev\napi\use-sendable-napi.md
// index.d.ets @Sendable export class MyObject { constructor(arg: number); plusOne(): number; public get value(); public set value(newVal: number); }
application-dev\napi\use-sendable-napi.md
import hilog from '@ohos.hilog'; import { MyObject } from 'libentry.so'; let object : MyObject = new MyObject(0); object.value = 1023; hilog.info(0x0000, 'testTag', 'MyObject value after set: %{public}d', object.value); hilog.info(0x0000, 'testTag', 'MyObject plusOne: %{public}d', object.plusOne());
application-dev\network\http-request.md
// Import the http namespace. import { http } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { common } from '@kit.AbilityKit'; let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; // Each httpRequest corresponds to an HTTP reque...
application-dev\network\http-request.md
// Import the http namespace. import { http } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; // Each httpRequest corresponds to an HTTP request task and cannot be reused. let httpRequest = http.createHttp(); // Subscribe to HTTP response header events. httpRequest.on('headersReceive', (...
application-dev\network\native-netmanager-guidelines.md
export const GetDefaultNet: (code: number) => number; export const NetId: () => number;
application-dev\network\native-netmanager-guidelines.md
import testNetManager from 'libentry.so'; @Entry @Component struct Index { @State message: string = ''; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) Button('GetDefaultNet').onClick(event => { this.GetDefaultNet()...
application-dev\network\native-websocket-guidelines.md
export const Connect: (url: string) => boolean; export const Send: (data: string) => number; export const Close: () => number;
application-dev\network\native-websocket-guidelines.md
import testWebsocket from 'libentry.so' @Entry @Component struct Index { @State wsUrl: string = '' @State content: string = '' @State connecting: boolean = false build() { Navigation() { Column() { Column() { Text("WebSocket address: ") .fontColor(Color.Gray) ...
application-dev\network\net-connection-manager.md
// Import the required namespaces. import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-connection-manager.md
let netSpecifier: connection.NetSpecifier = { netCapabilities: { // Assume that the default network is Wi-Fi. If you need to create a cellular network connection, set the network type to CELLULAR. bearerTypes: [connection.NetBearType.BEARER_CELLULAR], // Set the network capability to INTER...
application-dev\network\net-connection-manager.md
// Register an observer for network status changes. conn.register((err: BusinessError, data: void) => { console.log(JSON.stringify(err)); });
application-dev\network\net-connection-manager.md
// Subscribe to network status change events. If the network is available, an on_netAvailable event is returned. conn.on('netAvailable', ((data: connection.NetHandle) => { console.log("net is available, netId is " + data.netId); })); // Subscribe to network status change events. If the network is una...
application-dev\network\net-connection-manager.md
// Unregister the observer for network status changes. conn.unregister((err: BusinessError, data: void) => { });
application-dev\network\net-connection-manager.md
import { connection } from '@kit.NetworkKit'; async function test() { const netConnection = connection.createNetConnection(); /* Listen for changes of the default network */ netConnection.on('netAvailable', (data: connection.NetHandle) => { console.log(JSON.stringify(data)); }); }
application-dev\network\net-connection-manager.md
import { rcp } from '@kit.RemoteCommunicationKit'; import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; let session = rcp.createSession(); async function useRcp() { // Create an RCP request. // try { const request = await session.get('https://www.example.com'); ...
application-dev\network\net-connection-manager.md
import { connection, socket } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; let sock: socket.TCPSocket = socket.constructTCPSocketInstance(); async function useSocket() { let tcpConnectOptions: socket.TCPConnectOptions = { address: { address: '192.168.xx.xxx', port: ...
application-dev\network\net-connection-manager.md
// Import the required namespaces. import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-connection-manager.md
// Construct a singleton object. export class GlobalContext { public netList: connection.NetHandle[] = []; private constructor() {} private static instance: GlobalContext; private _objects = new Map<string, Object>(); public static getContext(): GlobalContext { if (!GlobalCont...
application-dev\network\net-connection-manager.md
import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-connection-manager.md
// Construct a singleton object. export class GlobalContext { public netList: connection.NetHandle[] = []; public netHandle: connection.NetHandle|null = null; private constructor() {} private static instance: GlobalContext; private _objects = new Map<string, Object>(); public st...
application-dev\network\net-connection-manager.md
// Call getAllNets to obtain the list of all connected networks specified by Array<NetHandle>. connection.getAllNets().then((data: connection.NetHandle[]) => { console.info("getAllNets get data: " + JSON.stringify(data)); if (data) { GlobalContext.getContext().netList = data; let itemNu...
application-dev\network\net-connection-manager.md
// Import the required namespaces. import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-connection-manager.md
judgeHasNet(): boolean { try { let netHandle = connection.getDefaultNetSync(); if (!netHandle || netHandle.netId === 0) { return false; } let netCapabilities = connection.getNetCapabilitiesSync(netHandle); let cap = netCapabilities.networkCap || []; if (!c...
application-dev\network\net-connection-manager.md
// Import the required namespaces. import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-connection-manager.md
// Use the default network to resolve the host name to obtain the list of all IP addresses. connection.getAddressesByName("xxxx").then((data: connection.NetAddress[]) => { console.info("Succeeded to get data: " + JSON.stringify(data)); });
application-dev\network\net-ethernet.md
// Import the ethernet namespace from @kit.NetworkKit. import { ethernet } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; // Call getAllActiveIfaces to obtain the list of all active network ports. ethernet.getAllActiveIfaces().then((data: string[]) => { console.log("getAllActiveIfaces...
application-dev\network\net-ethernet.md
// Import the ethernet namespace from @kit.NetworkKit. import { ethernet } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; // Call getAllActiveIfaces to obtain the list of all active network ports. ethernet.getAllActiveIfaces().then((data: string[]) => { console.log("getAllActiveIfaces...
application-dev\network\net-ethernet.md
// Import the ethernet namespace from @kit.NetworkKit. import { ethernet } from '@kit.NetworkKit'; // Subscribe to interfaceStateChange events. class EthernetData{ iface: string = "" active: boolean = false } ethernet.on('interfaceStateChange', (data: EthernetData) => { console.log(JSON.stringify(data)); }); /...
application-dev\network\net-mdns.md
// Import the mdns namespace from @kit.NetworkKit. import { mdns } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { featureAbility, common } from '@kit.AbilityKit'; let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; class Serv...
application-dev\network\net-mdns.md
// Import the mdns namespace from @kit.NetworkKit. import { common, featureAbility, UIAbility } from '@kit.AbilityKit'; import { mdns } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; // Construct a singleton object. export class GlobalContext { pri...
application-dev\network\net-netfirewall.md
// Import the netFirewall namespace from @kit.NetworkKit. import { netFirewall } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-netfirewall.md
interface IpType{ family:number; type:number; address?:string; mask?:number; startIp?:string; endIp?:string; } interface IpPort{ startPort:number; endPort:number; } // Define the firewall policy to enable the firewall and deny ...
application-dev\network\net-netfirewall.md
// Initialize firewall rules for specific types of IP addresses. let ipRule: netFirewall.NetFirewallRule = { name: "rule1", description: "rule1 description", direction: netFirewall.NetFirewallRuleDirection.RULE_IN, action:netFirewall.FirewallRuleAction.RULE_DENY, type: netFirewall.NetF...
application-dev\network\net-netfirewall.md
// Import the netFirewall namespace from @kit.NetworkKit. import { netFirewall } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-netfirewall.md
interface domain{ isWildcard: boolean; domain: string; } // Define the firewall policy to enable the firewall and deny inbound traffic while allowing outbound traffic. let policy: netFirewall.NetFirewallPolicy = { isOpen: true, inAction: netFirewall.FirewallRuleAction.RULE_DENY,...
application-dev\network\net-netfirewall.md
// Initialize firewall rules for specific types of domain names. let domainRule: netFirewall.NetFirewallRule = { name: "rule2", description: "rule2 description", direction: netFirewall.NetFirewallRuleDirection.RULE_IN, action:netFirewall.FirewallRuleAction.RULE_DENY, type: netFirewall....
application-dev\network\net-netfirewall.md
// Import the netFirewall namespace from @kit.NetworkKit. import { netFirewall } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit';
application-dev\network\net-netfirewall.md
// Call getInterceptedRecords to perform pagination query on firewall interception records. let interceptRecordParam: netFirewall.RequestParam = { page: 1, pageSize: 10, orderField: netFirewall.NetFirewallOrderField.ORDER_BY_RECORD_TIME, orderType: netFirewall.NetFirewallOrderType.ORDER_DESC...
application-dev\network\net-sharing.md
// Import the sharing namespace from @kit.NetworkKit. import { sharing } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; // Subscribe to network sharing state changes. sharing.on('sharingStateChange', (data: boolean) => { console.log(JSON.stringify(data)); }); // Call startSharing to ...
application-dev\network\net-sharing.md
// Import the sharing namespace from @kit.NetworkKit. import { sharing } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; // Subscribe to network sharing state changes. sharing.on('sharingStateChange', (data: boolean) => { console.log(JSON.stringify(data)); }); // Call stopSharing to s...
application-dev\network\net-sharing.md
// Import the sharing namespace from @kit.NetworkKit. import { sharing } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; // Call startSharing to start network sharing of the specified type. sharing.startSharing(sharing.SharingIfaceType.SHARING_WIFI).then(() => { console.log('start wifi...
application-dev\network\net-statistics.md
// Import the statistics namespace from @kit.NetworkKit. import { statistics, socket } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; // Obtain the real-time downlink data traffic of the specified NIC. statistics.getIfaceRxBytes("wlan0").then((stats: number) => { console.log(JSON.str...
application-dev\network\net-statistics.md
import { statistics } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; class IfaceInfo { iface: string = "wlan0" startTime: number = 1685948465 endTime: number = 16859485670 } // Obtain the historical data traffic of the specified NIC. statistics.getTrafficStatsByIface(new IfaceInf...
application-dev\network\net-statistics.md
import { statistics } from '@kit.NetworkKit'; class Data { iface: string = "" uid?: number = 0 } let callback = (data: Data) => { console.log('on netStatsChange, data:' + JSON.stringify(data)); }; // Subscribe to traffic change events. statistics.on('netStatsChange', callback); // Unsubscribe from traffic chan...