用户需求:ets文件中可以执行ping命令以获取更多网络状态
类似参考其他端调用ping命令方式
代码demo
Runtime.getRuntime().exec(“ping -c 1 -w 1 $host”).waitFor()
用户需求:ets文件中可以执行ping命令以获取更多网络状态
类似参考其他端调用ping命令方式
代码demo
Runtime.getRuntime().exec(“ping -c 1 -w 1 $host”).waitFor()
1 回答1.1k 阅读✓ 已解决
1 回答1.4k 阅读
1 回答1.2k 阅读
1 回答1.2k 阅读
1 回答1.2k 阅读
1 回答1k 阅读
1 回答1k 阅读
使用executeShellCommand方法执行相关命令,请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-inner-application-shellcmdresult-V5\#使用说明
目前HarmonyOS提供的可以执行命令的接口只有executeShellCommand。
单次获取可参考connetion模块内getNetCapabilities接口方法获取当前网络类型,返回参数中netBearType为当前网络类型,返回netCap为"[12,16]"时表示当前网络已连接且可使用,
请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-net-connection-V5\#connectiongetnetcapabilities
判断当前网络是否通畅,网络是否有变化,可以参考API:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-net-connection-V5\#netconnection