Connecting to Wifi with Huawei Scan Kit

Yağmur Kılıç
Huawei Developers
Published in
2 min readMay 20, 2021

--

This article is about connecting to the wireless network with the Huawei scan kit.

Huawei Scan Kit Integration

  1. Configure app information in AppGallery Connect
  2. Integrate the HMS Core SDK
  3. Assign permissions

Connecting to Wifi with Huawei Scan Kit

Add Required Permissions for Barcode Scanning and Wifi Connection to AndroidManifest.xml

Dynamically request the permissions in the MainActivity.java file

You can use the link for more detail about the required permissions.

In line 12, the scan process starts. HmsScanType value must set WIFI_CONNECT_INFO_FORM for getting information of wifi.

HmsScan.WiFiConnectionInfo

The sample barcode value is as follows.

  • Original value : WIFI:S:WIFI_123;T:WPA;P:12345678;;
  • Wi-Fi SSID : WIFI_123
  • Wi-Fi Password : 12345678
  • Wi-Fi encryption type : WPA

Data need to be parsed in onActivityResult to get the password and SSID.

You can use the android.net library to connect to wifi using the password and SSID.

The first step is to create a WifiNetworkSpecifier with the SSID and password obtained from the barcode.

The second step is to create a network request with the wifiNetworkSpecifier created in the previous step.

NetworkCallback is the base class for NetworkRequest. Used for notifications about network changes. Should be extended by applications wanting notifications.

If a network matching the SSID is found, connect to wireless network option will be shown. After clicking connect button, If the password is correct, it will be successfully connected to the network.

The following alert will be shown if a network matching the SSID cannot be found.

Use Cases

  • Sharing wifi with customers in the cafe and restaurant.
  • Sharing wifi with passengers in public transportation

Conclusion

I hope this article helps you better understand the usage scenarios of the Huawei scanning kit.

Thanks for reading. If you have a question, don’t hesitate to contact me.

--

--