4

I have some SSID which has no internet access, which I'm trying to connect programmatically from the android app. I'm supposed to make few api calls with that SSID though it has no internet. All works fine below android Q versions. There is some issue with the android Q version.

I'm using Retrofit for https communications.

I use WifiNetworkSpecifier and wifi manager to connect to the SSID(no internet) programmatically.

 WifiNetworkSpecifier specifier = new WifiNetworkSpecifier.Builder()
                .setSsid(ssid)
                .setWpa2Passphrase(password)
                .build();

NetworkRequest networkRequest = new NetworkRequest.Builder()
    .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
    .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
    .addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
    .setNetworkSpecifier(specifier)
    .build();


    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback()
   @Override
    public void onAvailable(Network network) {

    }
    @Override
    public void onUnavailable() {
        super.onUnavailable();

    }
    @Override
    public void onLost(Network network) {
    }
};
connectivityManager.requestNetwork(networkRequest, networkCallback, 30000
);

I am able to successfully connect to the wifi network from my code. But every time I make SSID api calls, I get "Unable to resolve host "URL". No address associated with hostname" issue in the retrofit onFailure() callback. But interestingly if I connect SSID from the phone settings app, I'm not seeing the unknown host exception and all works fine.

Can someone help me, in android Q what is so different connecting SSID programmatically than through android settings ? What else I need to change in order to fix this issue ?

hacker
  • 8,919
  • 12
  • 62
  • 108

1 Answers1

0

You can't fix this issue, it's a bug in Android 10, there's an issue opened in issueTracker, Google said that it's fixed but they didn't share the solution. Shame on you Google !

NizarETH
  • 969
  • 3
  • 15
  • 38