ThanosFisherman / WifiUtils

Easily Connect to WiFi Networks
Apache License 2.0
731 stars 188 forks source link

Android 9 Throttling #117

Closed fernando-s97 closed 2 years ago

fernando-s97 commented 2 years ago

image

In Android 9, when I execute the code below 5 times , in the 5th attempt, I won't be able to connect. That's because every time I make a connection, a scan is triggered. Why's that? Is it really necessary?

WifiUtils.withContext(requireContext())
            .connectWith("ssid", "pass")
            .setTimeout(5000)
            .onConnectionResult(object : ConnectionSuccessListener {
                override fun success() {
                    isConnected = true
                    Toast.makeText(activity, "Connect success!", Toast.LENGTH_SHORT)
                        .show()
                }

                override fun failed(errorCode: ConnectionErrorCode) {
                    Toast.makeText(
                        activity,
                        "Failed to connect: $errorCode",
                        Toast.LENGTH_SHORT
                    ).show()
                }
            })
            .start()