Package ej.ecom.wifi
Class WifiManager
- java.lang.Object
-
- ej.ecom.wifi.WifiManager
-
public class WifiManager extends Object
Manages the Wi-Fi capabilities.
-
-
Constructor Summary
Constructors Constructor Description WifiManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisableSoftAP()Disables the Software enabled Access Point (SoftAP).voidenableSoftAP(SoftAPConfiguration configuration)Enables the SoftAP with a given configuration.WifiCapabilitygetCapability()Gets the Wi-Fi capability of the platform.static WifiManagergetInstance()Returns theWifiManagerinstance.AccessPointgetJoined()Gets the currently joined Wi-Fi access point.booleanisSoftAPEnabled()Tells whether if SoftAP is currently enabled.voidjoin(AccessPoint accessPoint, String passphrase, SecurityMode securityMode)Joins a Wi-Fi network using a Wi-Fi access point, a passphrase and a security mode.voidjoin(String SSID, String passphrase)Joins a Wi-Fi network using a SSID and a passphrase.voidjoin(String SSID, String passphrase, SecurityMode securityMode)Joins a wireless network using an SSID and a passphrase.voidleave()Leaves the currently joined Wi-Fi access point.AccessPoint[]scan()Performs an active scan of available Wi-Fi access points.AccessPoint[]scan(boolean active)Performs a scan of available access points.
-
-
-
Method Detail
-
getInstance
public static WifiManager getInstance()
Returns theWifiManagerinstance.- Returns:
WifiManagerinstance.
-
disableSoftAP
public void disableSoftAP() throws IOExceptionDisables the Software enabled Access Point (SoftAP). This method has no effect if the SoftAP is not started.- Throws:
IOException- if an I/O error occurs
-
enableSoftAP
public void enableSoftAP(SoftAPConfiguration configuration) throws IOException
Enables the SoftAP with a given configuration.- Parameters:
configuration- SoftAP configuration.- Throws:
IOException- if SoftAP mode is not supported, an access point is currently joined and the platform does support simultaneous mode (leave()must be called before this method) or an I/O error occurs.
-
getCapability
public WifiCapability getCapability() throws IOException
Gets the Wi-Fi capability of the platform.- Returns:
- Wi-Fi capability.
- Throws:
IOException- If an I/O error occurs.
-
getJoined
@Nullable public AccessPoint getJoined() throws IOException
Gets the currently joined Wi-Fi access point.- Returns:
- currently joined Wi-Fi access point or
nullif no Wi-Fi access point has been joined yet. - Throws:
IOException- If an I/O error occurs.
-
isSoftAPEnabled
public boolean isSoftAPEnabled() throws IOExceptionTells whether if SoftAP is currently enabled.- Returns:
trueif enabled,falseotherwise.- Throws:
IOException- If an I/O error occurs.
-
join
public void join(AccessPoint accessPoint, String passphrase, SecurityMode securityMode) throws IOException
Joins a Wi-Fi network using a Wi-Fi access point, a passphrase and a security mode.- Parameters:
accessPoint- Wi-Fi access point.passphrase- Wi-Fi access point passphrase. The passphrase must be a sequence of between 8 and 64 ASCII-encoded characters.securityMode- Wi-Fi access point security mode.- Throws:
IOException- if client mode is not supported, the SoftAP is currently enabled and the platform does support simultaneous mode (disableSoftAP()must be called before this method), or an I/O error occurs.IllegalArgumentException- if the accessPoint or the passphrase isnull.
-
join
public void join(String SSID, String passphrase) throws IOException
Joins a Wi-Fi network using a SSID and a passphrase.- Parameters:
SSID- Wi-Fi access point Service Set Identifier (SSID).passphrase- Wi-Fi access point passphrase. The passphrase must be a sequence of between 8 and 64 ASCII-encoded characters.- Throws:
IOException- if client mode is not supported, the SoftAP is currently enabled and the platform does support simultaneous mode (disableSoftAP()must be called before this method), or an I/O error occurs.IllegalArgumentException- if the SSID or the passphrase isnull.
-
join
public void join(String SSID, String passphrase, SecurityMode securityMode) throws IOException
Joins a wireless network using an SSID and a passphrase.- Parameters:
SSID- Wi-Fi access point Service Set Identifier (SSID).passphrase- Wi-Fi access point passphrase. The passphrase must be a sequence of between 8 and 64 ASCII-encoded characters.securityMode- Wi-Fi access point security mode.- Throws:
IOException- if client mode is not supported, the SoftAP is currently enabled and the platform does support simultaneous mode (disableSoftAP()must be called before this method), or an I/O error occurs.IllegalArgumentException- if the SSID or the passphrase isnull.
-
leave
public void leave() throws IOExceptionLeaves the currently joined Wi-Fi access point. If no Wi-Fi access point has been joined yet, this method has no effect.- Throws:
IOException- If an I/O error occurs.
-
scan
public AccessPoint[] scan() throws IOException
Performs an active scan of available Wi-Fi access points. This is equivalent toscan(true).- Returns:
- the list of available Wi-Fi access points or an empty list if there is no available Wi-Fi access point.
- Throws:
IOException- if the underlying Wi-Fi network interface is currently stopped, scanning is not possible at the moment, or an I/O error occurs.
-
scan
public AccessPoint[] scan(boolean active) throws IOException
Performs a scan of available access points.- Parameters:
active-truefor an active scan,falsefor a passive scan.- Returns:
- the list of available access points or an empty list if there is no available Wi-Fi access point.
- Throws:
IOException- if the underlying network interface is currently stopped, scanning is not possible at the moment, or an I/O error occurs.
-
-