Checking if connected to WiFi
private boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
}
return haveConnectedWifi;
}
All you need to do is add this function in your java file and add the ACCESS NETWORK STATE permission in manifest file, and you are all set.
Written by iostreamer
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
Related Tags
#android
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#