Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[wifi_info_flutter] Wifi plugin implementation #3143

Merged
merged 11 commits into from
Oct 21, 2020
8 changes: 4 additions & 4 deletions packages/wifi_info_flutter/wifi_info_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ To successfully get WiFi Name or Wi-Fi BSSID starting with Android O, ensure all
You can get wi-fi related information using:

```dart
import 'package:connectivity/connectivity.dart';
import 'package:wifi_info_flutter/wifi_info_flutter.dart';

var wifiBSSID = await (WifiFlutter().getWifiBSSID());
var wifiIP = await (WifiFlutter().getWifiIP());
var wifiName = await (WifiFlutter().getWifiName());
var wifiBSSID = await WifiFlutter().getWifiBSSID();
var wifiIP = await WifiFlutter().getWifiIP();
var wifiName = await WifiFlutter().getWifiName();
```

### iOS 12
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.flutter.plugins.wifi_info_flutter">
Copy link
Member

@hamdikahloun hamdikahloun Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bparrishMines
To make the plugin work with Android 8.0 and Android 8.1 without additional steps, you can add that too: android.permission.CHANGE_WIFI_STATE .
https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-permissions
Thank you

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> to <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> .

Thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's best to leave permissions to the developer. I added the permission that was in the connectivity plugin to avoid breaking changes.

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

package io.flutter.plugins.wifi_info_flutter;

import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

/** Reports connectivity related information such as wifi information. */
/** Reports wifi information. */
class WifiInfoFlutter {
private WifiManager wifiManager;

Expand All @@ -15,7 +16,7 @@ class WifiInfoFlutter {
}

String getWifiName() {
android.net.wifi.WifiInfo wifiInfo = getWifiInfo();
final WifiInfo wifiInfo = getWifiInfo();
String ssid = null;
if (wifiInfo != null) ssid = wifiInfo.getSSID();
if (ssid != null) ssid = ssid.replaceAll("\"", ""); // Android returns "SSID"
Expand All @@ -24,7 +25,7 @@ String getWifiName() {
}

String getWifiBSSID() {
android.net.wifi.WifiInfo wifiInfo = getWifiInfo();
final WifiInfo wifiInfo = getWifiInfo();
String bssid = null;
if (wifiInfo != null) {
bssid = wifiInfo.getBSSID();
Expand All @@ -33,7 +34,7 @@ String getWifiBSSID() {
}

String getWifiIPAddress() {
android.net.wifi.WifiInfo wifiInfo = null;
final WifiInfo wifiInfo = null;
if (wifiManager != null) wifiInfo = wifiManager.getConnectionInfo();

String ip = null;
Expand All @@ -49,7 +50,7 @@ String getWifiIPAddress() {
return ip;
}

private android.net.wifi.WifiInfo getWifiInfo() {
private WifiInfo getWifiInfo() {
return wifiManager == null ? null : wifiManager.getConnectionInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class WifiInfoFlutterMethodChannelHandler implements MethodChannel.MethodCallHan
private WifiInfoFlutter wifiInfoFlutter;

/**
* Construct the ConnectivityMethodChannelHandler with a {@code connectivity}. The {@code
* connectivity} must not be null.
* Construct the WifiInfoFlutterMethodChannelHandler with a {@code wifiInfoFlutter}. The {@code
* wifiInfoFlutter} must not be null.
*/
WifiInfoFlutterMethodChannelHandler(WifiInfoFlutter wifiInfoFlutter) {
assert (wifiInfoFlutter != null);
Expand Down