I have an app which connects to a hardware device Wi-Fi hotspot. It seems that Android forward requests over other networks (3G/4G for example) instead the hotspot, since my
Use the ConnectivityManager to get the state of the Wifi adapter and then you can check if it is connected or even available using NetworkInfo.
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifi.isConnected()) {
// Continue with logic
}
In case he is not connected to wifi then don't proceed else continue you flow.
Add the following permission in you Manifest file