Last Updated on : 2024-07-15 09:45:16download
The alternative network feature provides the following capabilities:
Get the management class for alternative networks
val manager = DeviceBusinessDataManager.getInstance().getDeviceNetSetManager(deviceId)
Check support for alternative networks
val isSupport = manager?.isSupportBackupNetwork()
Implement the alternative network service as shown below only when the device supports it.
Get information about the Wi-Fi network the device is connected to.
manager?.getDeviceCurrentNetInfo(object : IThingDataCallback<CurrentWifiInfoBean?> {
override fun onSuccess(result: CurrentWifiInfoBean?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
Get the list of alternative Wi-Fi networks.
manager?.getDeviceBackupWiFiList(object : IThingDataCallback<BackupWifiListInfo?> {
override fun onSuccess(result: BackupWifiListInfo?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
Updating the list of alternative networks applies only when the device supports this feature. When the maximum number of alternative networks is reached, no additional networks can be added. You can check this with the maxNum
value returned in step 1.
manager?.canUpdateDeviceBackupWiFiList(bean)
To add an alternative Wi-Fi network, assemble the SSID, password, and hash value of the Wi-Fi network into a BackupWifiBean
and then invoke the method updateDeviceBackupWiFiList
.
// Assemble data
val backupWifiBean = BackupWifiBean()
backupWifiBean.ssid = ssid
backupWifiBean.passwd = pwd
backupWifiBean.hash =
SHA256Utils.getBase64Hash(viewModel.deviceBean?.getLocalKey() + ssid + pwd)
backupWifiBeans.add(backupWifiBean)
// Update the list
manager?.updateDeviceBackupWiFiList(backupWifiList,
object : IThingDataCallback<BackupWifiResultBean?> {
override fun onSuccess(result: BackupWifiResultBean?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
Switching the device’s network automatically applies only when the device supports this feature.
canSwitchDeviceWiFi.value = manager?.canSwitchDeviceWiFi(bean)
Switch the device’s network to a new Wi-Fi network or an alternative one.
manager?.switchToNewWifi(ssid, pwd, object : IThingDataCallback<SwitchWifiResultBean?> {
override fun onSuccess(result: SwitchWifiResultBean?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
manager?.switchToBackupWifi(hash, object : IThingDataCallback<SwitchWifiResultBean?> {
override fun onSuccess(result: SwitchWifiResultBean?) {
}
override fun onError(errorCode: String?, errorMessage: String?) {
}
})
This topic describes the service implementation in the sequence of read and create operations. In real-world projects, you can implement them as needed. For more information, see the Alternative Network Module in the BizBundle SDK Demo.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback