flutternetwork / WiFiFlutter

Flutter plugin suite for various WiFi services.
https://wifi.flutternetwork.dev
285 stars 177 forks source link

withInternet API is not working for Android 11 device #347

Open AbdulRahman577 opened 1 year ago

AbdulRahman577 commented 1 year ago

Hello Together, I'm working on Android 11 device which is POCO M2 Pro MIUI 12.5.6 Global version stable. I m developing app which is scanning the QR code to get WIFI credentials and then connect to those Wifi network. Wifi security type is WPA2. I m using qr scanner package and the wifi_iot package for connecting to the WiFi. When using the function, connectionstatus = await WiFiForIoTPlugin.findAndConnect(ssid, password: pwd );

It will connect to the network successfully but the internet access is not there. Then, I tried, connectionstatus = await WiFiForIoTPlugin.findAndConnect(ssid, password: pwd, withInternet: true); It does not even connecting to the network and debug console shows like below,

E/WifiIotPlugin( 4515): status: 0

It is quite same for the function Connect(),

  1. When connect withInternet:false, works fine. Connected to the network without internet.
  2. When connect withInternet:true, doesn't connect and return status:0 ( same as above faced in find and connect function)

I have used permission handler in run time for the location and also set everything in manifest file,

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"></uses-permission>

    <uses-feature android:name="android.hardware.wifi" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Please help me to find the solution.

DeepakStark123 commented 1 year ago

i am also facing the same issue i tried to fix it by changing the internal file also but still it not working please let me know if you have any solution for this

Y0ngg4n commented 7 months ago

Same issue here

JeanGC970520 commented 5 months ago

Hi!! I'm using the same package, this is the version: wifi_iot: ^0.3.19. I am not trying to acces to internet because my app doesn't need it. But I can connect it to the network and in my case, transmit data over a socket. This is my code that manage this:

Future<InternetState> tryWiFiConnection() async {

    try {

      logger.i("Trying connection process, connecting with: ${Environment.ssid}");
      final isConnected = await WiFiForIoTPlugin.findAndConnect(
        Environment.ssid!,
        password: Environment.password,
      );

      logger.i("WiFi connected: $isConnected");
      if( !isConnected ) return InternetState.disconnected; 

      await WiFiForIoTPlugin.forceWifiUsage(true);
      return InternetState.connected;

    }  on Exception catch (err) {
      logger.e("Fatal error on try WiFi Connection: $err");
      return InternetState.error;
    }

  }

Maybe it would work for you if you added: await WiFiForIoTPlugin.forceWifiUsage(true); You can see it in the package documentation.

(iv) Will have to use forceWifiUsage(true) to route app traffic via connected access point, similarly can be disabled to route traffic via cellular network (for internet). This is not enabled by default and left upto to the user.