How Can I Enforce Internet Connection Only Through Wifi?
We have a Wifi-connected device. We need to connect to the device via wifi for installation. Once connected, the application sends the request on a ip. This works smoothly before a
Solution 1:
I guess this is related to permissions since API level 27
you need either
android.permission.ACCESS_FINE_LOCATION
or
android.permission.ACCESS_COARSE_LOCATION
permission.
You need to CHANGE_WIFI_STATE
for Android Pie.
Try this
ConnectivityManagerconnManager= (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfonetworkInfo= connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
WifiManagerwifiManager= (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfowifiInfo= wifiManager.getConnectionInfo();
wifiInfo.getSSID();
Stringname= networkInfo.getExtraInfo();
Stringssid="\"" + wifiInfo.getSSID() + "\"";
}
You can study about these changes in detail. Refer Here
Post a Comment for "How Can I Enforce Internet Connection Only Through Wifi?"