Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanosFisherman committed Apr 25, 2020
1 parent f49e3a3 commit a6afdfa
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,48 @@ private void getScanResults(@NonNull final List<ScanResult> results)
Now lets get to the interesting stuff. You can connect to any WiFi network programmatically knowing only SSID and WPA/WPA2 key:

```java
WifiUtils.withContext(getApplicationContext())
.connectWith("MitsarasWiFi", "MitsarasPassword123")
.onConnectionResult(this::checkResult)
.start();
WifiUtils.withContext(getApplicationContext())
.connectWith("JohnDoeWiFi", "JohnDoePassword")
.setTimeout(40000)
.onConnectionResult(new ConnectionSuccessListener() {
@Override
public void success() {
Toast.makeText(MainActivity.this, "SUCCESS!", Toast.LENGTH_SHORT).show();
}

@Override
public void failed(@NonNull ConnectionErrorCode errorCode) {
Toast.makeText(MainActivity.this, "EPIC FAIL!" + errorCode.toString(), Toast.LENGTH_SHORT).show();
}
})
.start();
```

Again checkResult could be something like:
There are also a few other options that would allow you to do the same job: For example you can connect using SSID, BSSID and WPA/WPA2 Key:

Let's move the `ConnectionSuccessListener` from above into its own separate field named `successListener` so that we can save some space


```java
private void checkResult(boolean isSuccess)
{
if (isSuccess)
Toast.makeText(MainActivity.this, "CONNECTED YAY", Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "COULDN'T CONNECT", Toast.LENGTH_SHORT).show();
}
private ConnectionSuccessListener successListener = new ConnectionSuccessListener() {
@Override
public void success() {
Toast.makeText(MainActivity.this, "SUCCESS!", Toast.LENGTH_SHORT).show();
}

@Override
public void failed(@NonNull ConnectionErrorCode errorCode) {
Toast.makeText(MainActivity.this, "EPIC FAIL!" + errorCode.toString(), Toast.LENGTH_SHORT).show();
}
};
```

There are also a few other options that would allow you to do the same job: For example you can connect using SSID, BSSID and WPA/WPA2 Key:
Connection with both SSID and BSSID specified

```java
WifiUtils.withContext(getApplicationContext())
.connectWith("MitsarasWiFi", "AB:CD:EF:12:34:56", "MitsarasPassword123")
.onConnectionResult(this::checkResult)
.onConnectionResult(successListener)
.start();
```

Expand All @@ -90,7 +108,7 @@ Lastly WifiUtils can also connect using a specified `scanResult` after a WiFi Sc
```java
WifiUtils.withContext(getApplicationContext())
.connectWithScanResult("MitsarasPasword123", scanResults -> scanResults.get(0))
.onConnectionResult(this::checkResult)
.onConnectionResult(successListener)
.start();
```

Expand Down

0 comments on commit a6afdfa

Please sign in to comment.