Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BSSID to WifiResult #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions android/src/main/java/com/ly/wifi/WifiDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,11 @@ private void launchWifiList() {
level = 0;
}
HashMap<String, Object> maps = new HashMap<>();
if (key.isEmpty()) {
if (key.isEmpty() || scanResult.SSID.contains(key)) {
maps.put("ssid", scanResult.SSID);
maps.put("level", level);
maps.put("bssid", scanResult.BSSID);
list.add(maps);
} else {
if (scanResult.SSID.contains(key)) {
maps.put("ssid", scanResult.SSID);
maps.put("level", level);
list.add(maps);
}
}
}
}
Expand Down Expand Up @@ -260,11 +255,15 @@ private WifiConfiguration createWifiConfig(String ssid, String Password) {
if (tempConfig != null) {
wifiManager.removeNetwork(tempConfig.networkId);
}
config.preSharedKey = "\"" + Password + "\"";
if (Password != null && !Password.isEmpty()) {
config.preSharedKey = "\"" + Password + "\"";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
} else {
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
config.hiddenSSID = true;
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
Expand Down
7 changes: 6 additions & 1 deletion ios/Classes/WifiPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSDictionary* argsMap = call.arguments;
NSString *ssid = argsMap[@"ssid"];
NSString *password = argsMap[@"password"];
NEHotspotConfiguration * hotspotConfig = [[NEHotspotConfiguration alloc] initWithSSID:ssid passphrase:password isWEP:NO];
NEHotspotConfiguration *hotspotConfig;
if ([password length] == 0) {
hotspotConfig = [[NEHotspotConfiguration alloc] initWithSSID:ssid];
} else {
hotspotConfig = [[NEHotspotConfiguration alloc] initWithSSID:ssid passphrase:password isWEP:NO];
}
[[NEHotspotConfigurationManager sharedManager] applyConfiguration:hotspotConfig completionHandler:^(NSError * _Nullable error) {
if(error == nil){
result(@1);
Expand Down
13 changes: 8 additions & 5 deletions lib/wifi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ class Wifi {
var results = await _channel.invokeMethod('list', params);
List<WifiResult> resultList = [];
for (int i = 0; i < results.length; i++) {
resultList.add(WifiResult(results[i]['ssid'], results[i]['level']));
resultList.add(WifiResult(results[i]['ssid'], results[i]['level'], results[i]['bssid']));
}
return resultList;
}

static Future<WifiState> connection(String ssid, String password) async {
static Future<WifiState> connection(String ssid, [String password]) async {
final Map<String, dynamic> params = {
'ssid': ssid,
'password': password,
'ssid': ssid
};
if (password != null && password.isNotEmpty) {
params.addEntries([MapEntry('password', password)]);
}
int state = await _channel.invokeMethod('connection', params);
switch (state) {
case 0:
Expand All @@ -53,6 +55,7 @@ class Wifi {
class WifiResult {
String ssid;
int level;
String bssid;

WifiResult(this.ssid, this.level);
WifiResult(this.ssid, this.level, this.bssid);
}