| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 36 | 33 | ||
| entry/ | 06-May-2025 | - | 2,094 | 1,964 | ||
| hvigor/ | 06-May-2025 | - | 23 | 22 | ||
| screenshots/device/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 182 | 14 | 13 | |
| README.md | D | 06-May-2025 | 1.1 KiB | 20 | 10 | |
| README_zh.md | D | 06-May-2025 | 5.7 KiB | 95 | 64 | |
| build-profile.json5 | D | 06-May-2025 | 1 KiB | 42 | 41 | |
| hvigorfile.ts | D | 06-May-2025 | 158 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 810 | 27 | 25 | |
| ohosTest.md | D | 06-May-2025 | 937 | 12 | 10 |
README.md
1# WLAN 2 3### Introduction 4 5This sample shows how to use WLAN with eTS, including disabling and enabling the WLAN, scanning the WLAN and obtaining the scanning result, listening for WLAN status and Wi-Fi connection status, obtaining the IP address, country code, and checking whether the device supports WLAN features. 6 7### Usage 8 91. After the app is started, it checks whether the WLAN is activated. If it is activated, the app scans for available Wi-Fi networks and displays the list of available and connected Wi-Fi networks. 10 112. Touch the toggle on the page to enable or disable the WLAN. The device listens for the WLAN statue, scans for available Wi-Fi networks, and displays the connected Wi-Fi network. 12 133. Touch a Wi-Fi network in the list of available Wi-Fi networks to connect to the Wi-Fi network. If the Wi-Fi network is encrypted, a dialog box will be displayed asking you to enter the password. 14 154. Touch **About** in the upper right corner of the home page. The obtained IP address, country code, and supported WLAN features are displayed. 16 17### Constraints 18 19This sample can only be run on standard-system devices. 20
README_zh.md
1# WLAN(仅对系统应用开放) 2 3### 介绍 4 5本示例通过[@ohos.wifiManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-connectivity-kit/js-apis-wifiManager.md) 相关API实现wlan激活和关闭、扫描和连接WIFI等功能。 6 7### 效果预览 8 9|连接wifi |主页 |wifi详情 | 10|---------------------------------------------|---------------------------------------|-----------------------------------------| 11|||| 12 13使用说明 14 151. 启动应用后会判断WLAN是否激活,如果是激活状态,会扫描并展示可用WiFi列表,同时获取已连接WiFi信息并展示; 16 172. 点击界面的Switch开关可以禁用和激活WLAN,界面会监听WLAN状态扫描可用WiFi列表,也会监听WiFi连接状态展示已连接WiFi; 18 193. 点击可用WLAN列表中的WLAN信息,可以连接WiFi,如果是加密类型,会弹窗输入密码后连接; 20 214. 点击首页右上角的**关于**图标,进入关于界面,展示获取的IP信息、国家码和支持WLAN相关特性信息。 22 23### 工程目录 24``` 25entry/src/main/ets/ 26|---component 27| |---AvailableWifi.ets // 热点信息列表 28| |---BasicDataSource.ets // 热点列表懒加载 29| |---InfoView.ets // 列表中的每一项热点的展示栏 30| |---PswDialog.ets // 输入密码的弹窗 31| |---TitleBar.ets // 页面头部组件 32| |---WifiView.ets // 已连接的wifi的详情页 33|---entryability 34| |---EntryAbility.ets // 应用入口,在这里请求相关权限和进入首页 35|---model 36| |---Logger.ets // 日志文件 37| |---WifiModel.ets // 封装了wifi的接口 38|---pages 39| |---About.ets // wifi详情页 40| |---Index.ets // 首页 41``` 42 43### 具体实现 44 45* wlan激活和关闭功能:点击首页的切换按钮,如果是打开,使用wifi.enableWifi()开启wifi;如果是关闭,则使用wifi.disconnect()断开wifi, 46然后使用wifi.disableWifi()关闭wifi, 47源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) 。 48 49* wifi的连接、扫描、获取详细信息等功能封装在WifiModel模块中,源码参考:[WifiModel.ets](entry/src/main/ets/model/WifiModel.ets) 。 50 * wifi的连接功能:点击wifi列表中加密的wifi,并在弹窗中输入密码后,会在[AvailableWifi.ets](entry/src/main/ets/component/AvailableWifi.ets) 中通过WifiModule.connectNetwork()调用wifi.connectToDevice()连接wifi,如图中的**连接wifi**。 51 * wifi的扫描功能:进入[Index.ets](entry/src/main/ets/pages/Index.ets) 后就会间歇性的调用wifi.scan()开启扫描,然后通过WifiModel模块中的getScanInfos()调用wifi.getScanResults()来获取扫描的结果,如图中的**主页**。 52 * 获取wifi的详细信息:在[About.ets](entry/src/main/ets/pages/About.ets) 中通过WiFiModel中的getIpInfo()、getCountryCode()、getFeatureSupport()分别调用wifi.getIpInfo()、wifi.getCountryCode()、wifi.isFeatureSupported()来获取对应信息。 53 如图中的**wifi详情**。 54 55### 相关权限 56 57[ohos.permission.GET_WIFI_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionget_wifi_info) 58 59[ohos.permission.GET_WIFI_INFO_INTERNAL](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_wifi_info_internal) 60 61[ohos.permission.SET_WIFI_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionset_wifi_info) 62 63[ohos.permission.GET_WIFI_CONFIG](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_wifi_config) 64 65[ohos.permission.SET_WIFI_CONFIG](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionset_wifi_config) 66 67[ohos.permission.MANAGE_WIFI_CONNECTION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanage_wifi_connection) 68 69[ohos.permission.APPROXIMATELY_LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionapproximately_location) 70 71### 依赖 72 73不涉及。 74 75### 约束与限制 76 771. 本示例仅支持标准系统上运行。 78 792. 本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)才可编译运行。 80 813. 本示例已适配API version 9版本SDK,版本号:3.2.11.9,本示例需要使用@ohos.wifi系统权限的系统接口。使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md/) 。 82 834. 本示例需要使用ohos.permission.GET_WIFI_INFO_INTERNAL、ohos.permission.MANAGE_WIFI_CONNECTION的权限为system_core级别(相关权限级别可通过[权限定义列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md) 查看),需要手动配置对应级别的权限签名。 84 85### 下载 86 87如需单独下载本工程,执行如下命令: 88 89``` 90git init 91git config core.sparsecheckout true 92echo code/SystemFeature/Connectivity/Wlan/ > .git/info/sparse-checkout 93git remote add origin https://gitee.com/openharmony/applications_app_samples.git 94git pull origin master 95```