WiFiFlutter icon indicating copy to clipboard operation
WiFiFlutter copied to clipboard

[wifi_iot] Android 11 use "WiFiForIoTPlugin.connect(ssid,pw)" can not "real" connect

Open LINHANKK opened this issue 1 year ago • 4 comments

Android 11 XiaoMi A1

When I press connect button in wifi_iot Example, popup a dialog "wants to use a temporary WIFI net work in your device.....", And When I connect,and toast connection sucessful, but I can not see a wifi icon in Android Native Status Bar In Settings-WIFI, this connected WIFI item-summary show "Connected via router" And Unable to access the internet But When I connect this WIFI by maunal,Android Native Status Bar show icon and I can access the internet

Permission

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
    <uses-permission android:name="android.permission.INTERNET" />

Looking forward to recovery,Thank you!

LINHANKK avatar Mar 24 '23 10:03 LINHANKK

I'm also face this problem.

himanshujjp avatar Mar 28 '23 05:03 himanshujjp

I have the same issue using the code below try { if (await Permission.location.request().isGranted) { await WiFiForIoTPlugin.connect(state.evWifiName, password: state.evWifiPassword, joinOnce: false, security: NetworkSecurity.WPA) .then((value) async { if (value) { WiFiForIoTPlugin.forceWifiUsage(false); } }); } } catch (e) { print(e); print('error occurred'); }

I have tried setting withInternet:true however every time I do this, nothing happens but I get status 0 in the console. Any thoughts?

GivDavidL avatar Apr 25 '23 08:04 GivDavidL

See comment in #346 Looks like on Android you have to use "findAndConnect" and then forceWifi.

kodejack avatar Sep 07 '23 21:09 kodejack

Hello @kodejack , I appreciate your suggestion, and I did try using "findAndConnect," which did work. However, I'm encountering a different issue. In my case, I'm already connected to a Wi-Fi network (let's call it "X") outside the app, and "findAndConnect" does not disconnect the device from "X" and connect it to my desired network.

I've attempted the following

:Using the "disconnect" function, but it's returning "false" for some reason.

:Fetching the SSID using "getSSID" and attempting to remove the network. However, I could fetch the SSID but couldn't disconnect using "removeWifiNetwork.

"To clarify, my goal is to connect to a particular network (let's call it "Y"). If we are already connected to "X," I want to disconnect from that network and connect to "Y."

Thank you for your assistance.

AnshulMV avatar Sep 12 '23 13:09 AnshulMV