Skip to content

Commit

Permalink
Merge pull request #113 from Smeat/android10
Browse files Browse the repository at this point in the history
Fix connection on android 10
  • Loading branch information
voroshkov authored May 4, 2020
2 parents d8abb07 + 44af585 commit 2142355
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ private boolean checkIsWifiOnAndConnected() {
WifiManager wifiMgr = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
if (!wifiMgr.isWifiEnabled()) return false; // Wi-Fi adapter is OFF

WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
return wifiInfo.getNetworkId() != -1; // if true, then connected to an access point
ConnectivityManager cm =
(ConnectivityManager)getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
// Deprecated in Android 10, but should still be fine
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
return isConnected;
}

private String getGatewayIP() {
Expand Down

0 comments on commit 2142355

Please sign in to comment.