Here, my android device supports both wifi and 3g. At particular time which network is available on this device. Because my requirement is when 3g is available I have to upl
You need to add below permission in android manifest file:
After that you can use below functions to check wifi or mobile network is connected or not
public static boolean isWifiConnected(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return ((netInfo != null) && netInfo.isConnected());
}
public static boolean isMobileConnected(Context context) {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
return ((netInfo != null) && netInfo.isConnected());
}
Some references from developer.android.com are: