How i can know device is connected to Wifi or 3G, programmatically
Thanks
How i can know device is connected to Wifi or 3G, programmatically
Thanks
you can use WifiManager class as mentioned here
Edit: by calling getConnectionInfo() function of WifiManager class you will get WifiInfo object
WifiInfo has function getBSSID() which gives you connected AP's name
if its null that means it is not connected to any AP via Wifi ( Wifi is not enabled )
btw while looking for more info, i found this which should answer all your questions about mobile connectivity and wifi connectivity
here is my working sample:
public boolean isNetworkTypeMobile() {
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm!=null && cm.getActiveNetworkInfo()!=null && isNetworkTypeMobile(cm.getActiveNetworkInfo().getType()));
}
public static boolean isNetworkTypeMobile(int networkType) {
switch (networkType) {
case ConnectivityManager.TYPE_MOBILE: //0
case ConnectivityManager.TYPE_MOBILE_MMS: //2
case ConnectivityManager.TYPE_MOBILE_SUPL: //3
case ConnectivityManager.TYPE_MOBILE_DUN: //4
case ConnectivityManager.TYPE_MOBILE_HIPRI: //5
case 10:
case 11:
case 12:
case 14:
return true;
default:
return false;
}
}