Wi-Fi
You can connect to a Wireless Local Area Network (WLAN) and transfer data over the network. The Wi-Fi Manager enables your application to activate and deactivate a local Wi-Fi device and to scan for available access points.
The main features of the Tizen.Network.WiFi namespace includes the following:
-
Wi-Fi device management
You can use the Tizen.Network.WiFi.WiFiManager class to control the aspects of your application’s wireless connection. The aspects are described below:
- Activate or deactivate Wi-Fi, monitor connection state changes, and scan for available access points.
- Get BSSID asynchronously as well as synchronously.
- Make connections between an access point (AP) and wireless devices faster and easier using Wi-Fi Protected Setup (WPS).
-
Access point management
With the Tizen.Network.WiFi.WiFiAP class, you can connect to a specific access point, manage the Wi-Fi access point and security information. In order to do these, follow the steps below:
-
Access point details are instances of the Tizen.Network.WiFi.WiFiNetwork class, which allows you to retrieve various access point information, such as the SSID, frequency band, and maximum speed of the access point.
-
Access point security details are instances of the Tizen.Network.WiFi.WiFiSecurity class, which allows you to retrieve security information, such as the used encryption type and whether WPS is supported.
You can also obtain EAP information, which is encapsulated in the Tizen.Network.WiFi.WiFiEap class.
Table: Access point EAP information
You can scroll this table.Information Description Authentication type Wi-Fi EAP phase2 authentication type EAP type Wi-Fi EAP type CA certificate EAP CA certificate (valid only if the EAP type is TLS) Client certificate EAP client certificate (valid only if the EAP type is TLS) Passphrase EAP passphrase (valid if the EAP type is PEAP or TTLS) Private key file EAP private key file (valid only if the EAP type is TLS)
To create a
Tizen.Network.WiFi.WiFiAP
instance, use its constructor with the ESSID, or retrieve the instance from theGetFoundAPs()
method of theTizen.Network.WiFi.WiFiManager
class. -
The application uses the infrastructure mode to connect to a wireless local area network (WLAN). The infrastructure mode requires a wireless access point. To connect to a WLAN, the application client must be configured to use the same service set identifier (SSID) as the access point.
NoteYou can test the Wi-Fi functionality on a target device only. The emulator does not support this feature.
Prerequisites
To enable your application to use the Wi-Fi functionality, follow these steps:
-
To use the Tizen.Network.WiFi namespace, the application has to request permission by adding the following privileges to the
tizen-manifest.xml
file:XMLCopy<privileges> <privilege>http://tizen.org/privilege/network.get</privilege> <privilege>http://tizen.org/privilege/network.set</privilege> <privilege>http://tizen.org/privilege/network.profile</privilege> </privileges>
-
To use the methods and properties of the Tizen.Network.WiFi namespace, include it in your application:
C#Copyusing Tizen.Network.WiFi;
Manage events
To manage events related to Wi-Fi operations, use event handlers registered to the following events of the Tizen.Network.WiFi.WiFiManager class:
DeviceStateChanged
is called when the device state changes (Wi-Fi is activated or deactivated).ConnectionStateChanged
is called when the device access point connection state changes (connection to an access point is formed or lost).RssiLevelChanged
is called when the RSSI of the connected Wi-Fi changes.BackgroundScanFinished
is called when a background scan has finished.
To manage device and connection state events, follow these steps:
-
Define event handlers:
C#Copypublic static void EventHandlerDeviceStateChanged(object sender, EventArgs e) { Console.WriteLine("Device state: " + e.State); } public static void EventHandlerConnectionStateChanged(object sender, EventArgs e) { Console.WriteLine("WiFi connection state: " + e.State); }
-
Register the event handlers for the
DeviceStateChanged
andConnectionStateChanged
events of theTizen.Network.WiFi.WiFiManager
class:C#CopyWiFiManager.DeviceStateChanged += EventHandlerDeviceStateChanged; WiFiManager.ConnectionStateChanged += EventHandlerConnectionStateChanged;
-
When they are no longer needed, deregister the event handlers:
C#CopyWiFiManager.DeviceStateChanged -= EventHandlerDeviceStateChanged; WiFiManager.ConnectionStateChanged -= EventHandlerConnectionStateChanged;
Activate a Wi-Fi device
To activate a Wi-Fi local device and check the connection state, follow these steps:
-
Activate a Wi-Fi device using the asynchronous
ActivateAsync()
method of the Tizen.Network.WiFi.WiFiManager class:C#Copytry { await WiFiManager.ActivateAsync();
-
Check whether the connection has been made by using the
IsActive
property of theTizen.Network.WiFi.WiFiManager
class:C#Copyif (WiFiManager.IsActive) { Console.WriteLine("WiFi is activated"); } } catch (Exception e) { Console.WriteLine("Exception occurred" + e.ToString()); }
Scan for access points
To scan nearby access points and get their details, follow these steps:
-
Scan nearby access points using the
ScanAsync()
method of the Tizen.Network.WiFi.WiFiManager class:C#Copytry { await WiFiManager.ScanAsync();
-
Retrieve the scan results (the found access points) with the
GetFoundAPs()
method of theTizen.Network.WiFi.WiFiManager
class.In the following example, the application displays the name and connection state of each access point it finds. You can also get other information, such as the used frequency or the maximum speed the access point supports:
C#Copyvar apList = WiFiManager.GetFoundAPs(); foreach (var item in apList) { Console.WriteLine("AP name: " + item.NetworkInformation.Essid); Console.WriteLine("Connection state: " + item.NetworkInformation.ConnectionState); } } catch (Exception e) { Console.WriteLine("Exception occurred" + e.ToString()); }
Connect to a specific access point
To make a connection using a specific access point, follow the steps below:
-
Scan nearby access points using the
ScanAsync()
method of the Tizen.Network.WiFi.WiFiManager class, and select the one you want:C#Copytry { string ap = "APName"; WiFiAP connectAP; await WiFiManager.ScanAsync(); var apList = WiFiManager.GetFoundAPs(); foreach (var item in apList) { if (item.NetworkInformation.Essid == ap) { connectAP = item; break; } } } catch (Exception e) { Console.WriteLine("Exception occurred" + e.ToString()); }
-
Establish a connection with the selected access point:
C#Copytry { await connectAP.ConnectAsync(); } catch (Exception e) { Console.WriteLine("Exception occurred" + e.ToString()); }
-
Check whether the connection has been established successfully:
C#Copytry { WiFiAP connect = WiFiManager.GetConnectedAP(); if (connect.NetworkInformation.Essid == ap) { Console.WriteLine("Connection is successful"); } } catch (Exception e) { Console.WriteLine("Exception occurred" + e.ToString()); }
Deactivate a Wi-Fi device
To deactivate Wi-Fi when it is no longer needed (or the application is exiting), use the asynchronous DeactivateAsync()
method of the Tizen.Network.WiFi.WiFiManager class:
C#
Copy
try
{
await WiFiManager.DeactivateAsync();
}
catch (Exception e)
{
Console.WriteLine("Exception occurred" + e.ToString());
}
Related information
- Dependencies
- Tizen 4.0 and Higher