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 upload small amount of data. when wifi is available entire data have to upload. So, I have to check connection is wifi or 3g. Please help me. Thanks in advance.
+4
A:
Take a look at that
http://stackoverflow.com/questions/2789612/how-can-i-check-whether-an-android-device-is-connected-to-the-web
http://stackoverflow.com/questions/3119607/how-to-be-notified-on-wifi-network-status-change
http://stackoverflow.com/questions/3211978/how-to-check-internet-connectivity-in-android
http://stackoverflow.com/questions/2919414/get-network-type
http://stackoverflow.com/search?q=ConnectivityManager
Fedor
2010-07-16 07:34:42
+5
A:
I use this:
/**
* Checks if we have a valid Internet Connection on the device.
* @param ctx
* @return True if device has internet
*
* Code from: http://www.androidsnippets.org/snippets/131/
*/
public static boolean haveInternet(Context ctx) {
NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null || !info.isConnected()) {
return false;
}
if (info.isRoaming()) {
// here is the roaming option you can change it if you want to
// disable internet while roaming, just return false
return false;
}
return true;
}
Pentium10
2010-07-16 07:42:39