Android ... How To Find Out If I'm On A Wifi Internet?
In my application I just need to know if the device is connected to wifi network or not. I think this function works on emulator but not on real device. public static boolean wifi
Solution 1:
Try this:
publicbooleanisUsingWiFi() {
ConnectivityManagerconnectivity= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfowifiInfo= connectivity
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (wifiInfo != null && wifiInfo.getState() == NetworkInfo.State.CONNECTED
|| wifiInfo.getState() == NetworkInfo.State.CONNECTING) {
returntrue;
}
returnfalse;
}
You can also use the same for the mobile type:
publicbooleanisUsingMobileData() {
ConnectivityManagerconnectivity= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfomobileInfo= connectivity
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (mobileInfo != null && mobileInfo.getState() == NetworkInfo.State.CONNECTED
|| mobileInfo.getState() == NetworkInfo.State.CONNECTING) {
returntrue;
}
returnfalse;
}
Post a Comment for "Android ... How To Find Out If I'm On A Wifi Internet?"