If you have any questions or issues please email me at jschieck@gmail.com and thanks for your support!
NOTICE: Unity 2018.2 is not fully supported due to this bug.
Welcome to the Android Wifi Manager documentation page. Android Wifi Manager provides access to the WifiManager class on the Android platform. This allows control over the devices wifi enabled/disabled state, scanning for nearby wifi networks, and connecting to them.
After importing the package, a dialog prompt will appear asking to add the required permissions to the AndroidManifest.xml file located at Plugins/Android/AndroidManifest.xml. If there isn't already a manifest file in the project, a template provided in the plugin will be copied there. If for some reason the dialog does not automatically pop-up, it can be accessed via Window/Android Wifi Manager/Setup Permissions... This can also be used to re-run the setup process at any time.
Settings for this setup process are stored in ProjectSettings/AndroidWifiManager.asset.
Three Android permissions are required for full functionality of the plugin.
All classes in the plugin are located in the FSG.Android.Wifi
namespace.
using FSG.Android.Wifi;
to the top of code files for easy access.All functionality can be accessed on the static class AndroidWifiManager
.
AndroidWifiManager.SetWifiEnabled(bool enabled)
private void Start() { // Start the scan StartCoroutine(PrintWifiNetworks()); } private IEnumerator PrintWifiNetworks() { // Check if wifi is enabled if (AndroidWifiManager.IsWifiEnabled() == false) { // If not, enable it AndroidWifiManager.SetWifiEnabled(true); // Give the device time to enable wifi yield return new WaitForSeconds(1); } // Initiate a scan (not always needed) AndroidWifiManager.StartScan(); // Wait for the scan to complete yield return new WaitForSeconds(1); // Get the list of scan results var results = AndroidWifiManager.GetScanResults(); foreach (AndroidWifiScanResults result in results) { Debug.LogFormat("SSID: {0} Signal: {1}dBm Security Type: {2}", result.SSID, result.level, result.securityType); } }
private void Start() { // Connect to the network StartCoroutine(ConnectToWifi("My Wifi Network", "mywifipassword")); } // Connects to the target SSID network // NOTE: passwords are not required if the network returns AndroidWifiSecurityType.OPEN from scan results private IEnumerator ConnectToWifi(string ssid, string password = "") { // Check if wifi is enabled if (AndroidWifiManager.IsWifiEnabled() == false) { // If not, enable it AndroidWifiManager.SetWifiEnabled(true); // Give the device time to enable wifi yield return new WaitForSeconds(1); } // Connect to the network with the provided password var result = AndroidWifiManager.Connect(ssid, password); if (result == AndroidWifiManager.ConnectResult.SUCCESS) { Debug.LogFormat("Successfully connected to network {0}", ssid); } else { Debug.LogErrorFormat("Unable to connect to network {0}: Reason: {1}", ssid, result); } }
If you have any questions or issues please email me at jschieck@gmail.com and thanks for your support!