public class WifiConnector
extends java.lang.Object
WifiConnector
is instantiated with the SSID and a PSK of a Wifi
network. Once you have an instance, you can call either
connect()
which is blocking for a maximum of 10
seconds or you utilize
connect(IWifiConnectorCallback)
to get
asynchronously informed via a listener (the max 10 seconds timeout applies
here too).
You can also check if you are currently connected to a WiFi network via
isConnected()
.
Note that this class is not reusable. Reinstantiate after use!Modifier and Type | Class and Description |
---|---|
static interface |
WifiConnector.IWifiConnectorCallback |
Constructor and Description |
---|
WifiConnector(ConnectivityManager connectivityManager,
WifiManager wifiManager,
java.lang.String ssid,
java.lang.String psk) |
Modifier and Type | Method and Description |
---|---|
boolean |
connect()
Connects to the network.
|
void |
connect(WifiConnector.IWifiConnectorCallback callback)
Connects to the network (same as connect(boolean) but with async api)
|
boolean |
isConnected()
Checks if the android device is connected to the desired SSID (from
constructor).
|
void |
removeAddedWifiConfiguration()
When using {WifiConnector#connect} a WifiConfiguration is added to the system.
|
java.lang.String |
toString() |
public WifiConnector(ConnectivityManager connectivityManager, WifiManager wifiManager, java.lang.String ssid, java.lang.String psk)
connectivityManager
- android's connectivity manager servicewifiManager
- android's wifi manager servicessid
- the network's SSIDpsk
- the network's pre shared key. If empty string or null, the
network is assumed to be an open network without any
encryptionpublic void removeAddedWifiConfiguration()
public boolean isConnected()
public void connect(WifiConnector.IWifiConnectorCallback callback)
callback
- the callback to be called when the connect operation finishedpublic boolean connect()
public java.lang.String toString()
toString
in class java.lang.Object