1

In Android Q, I can scan, select and connect to wifi via programmatically. But I am not able to get the internet via the wifi I connected even tho it has internet access.

Below is my code:

 val wifiNetworkSpecifier = WifiNetworkSpecifier.Builder()
            .setSsid("Wifi-SSID")
            .setWpa2Passphrase("WiFi-password")
            .build()


val networkRequest = NetworkRequest.Builder()
            .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
            .setNetworkSpecifier(wifiNetworkSpecifier)
            .build()

var connectivityManager =
            applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

var connectivity = object : ConnectivityManager.NetworkCallback() {
            override fun onAvailable(network: Network) {
                Log.d("TAG: ", "Connected")
                connectivityManager.bindProcessToNetwork(network)
                super.onAvailable(network)
            }

            override fun onUnavailable() {
                super.onUnavailable()
                Log.d("TAG: ", "Not able to connect")
            }

            override fun onLost(network: Network) {
                Log.d("TAG: ", "Connection lost")
            }
        }
connectivityManager?.requestNetwork(networkRequest, connectivity)

TIA

  • How exactly did you determine you are not connected to the internet? – greeble31 Feb 14 '20 at 14:42
  • @greeble31 I had added one more simple button which open a webview with Url: https://www.google.com – Shehzab Ahammad Feb 15 '20 at 05:42
  • How do you know the phone is capable of internet access when your app is not involved? – greeble31 Feb 15 '20 at 14:07
  • For example I connected to ABC wifi manually and tried to open google.com thru Chrome browser and it worked. Then I tried to reconnet the same wifi thru my app and its connected successfully but I am not able to access google.com as its shows no internet available – Shehzab Ahammad Feb 16 '20 at 14:54
  • I had read a couple of articles says that this is an Android Q bug and will be fixed in couple of months. So is there any workaround that I can follow? – Shehzab Ahammad Feb 17 '20 at 05:47
  • Hmm, please mention some of those articles, because I have never heard of this. – greeble31 Feb 17 '20 at 13:16
  • https://issuetracker.google.com/issues/138335744 --> please go through this link – Shehzab Ahammad Feb 18 '20 at 05:41
  • I think [this comment](https://issuetracker.google.com/issues/138335744#comment8) answers your question. You cannot do this, using this API, in Android Q. – greeble31 Feb 18 '20 at 13:54
  • Can you re-share the link, I am getting Access denied pop-up message. – Shehzab Ahammad Feb 19 '20 at 04:06
  • Now the original link is blocked as well :) I think we broke it :) IIRC, it said the internet access was intentionally disabled when using `requestNetwork()` to force a connection to a given access point, and that internet would only be available to networks cooperatively chosen with input from the user, such as via the [Wi-Fi suggest](https://developer.android.com/guide/topics/connectivity/wifi-suggest.md) API. See also [this doc](https://developer.android.com/about/versions/10/features#peer2peer). – greeble31 Feb 19 '20 at 13:33
  • I even tried with [Wi-Fi suggest](https://developer.android.com/guide/topics/connectivity/wifi-suggest.md) API. But it doesn't work for me. – Shehzab Ahammad Feb 20 '20 at 10:50

0 Answers0