My application has some code which detects if the Android device is
connected to a Wi-Fi or Mobile network.
The code appeared to be working fine for Andoid 1.5, but does not seem
to work correctly for Andorid 1.6.
Here is the code I am using:
private static void updateWiFiConnectionState(Context context) {
try {
ConnectivityManager connectivityManager =
(ConnectivityManager)
context.getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo networkInfo =
connectivityManager.getActiveNetworkInfo
();
boolean hasActiveWiFiConnection = false;
if ((networkInfo != null) && networkInfo.isConnected()
&&
(networkInfo.getType() ==
ConnectivityManager.TYPE_WIFI)) {
hasActiveWiFiConnection = true;
}
Log.d(TAG, "Wi-Fi connected state set to " +
hasActiveWiFiConnection);
setWiFiConnectionState(context,
hasActiveWiFiConnection);
} catch (Exception e) {
Log.e(TAG, "Exception " + e.getMessage() + " while getting Wi-Fi
state");
setWiFiConnectionState(context, false);
}
}
Under Android 1.5 this code would correctly detect if the current
connectivity was Wi-Fi or Mobile. However under Android 1.6 the call
to getActiveNetworkInfo seems to always return a networkInfo instance
with the type set to TYPE_MOBILE. This is happening even though the
icons in the bar at the top of the android screen show the Wi-Fi
connected icon with the full signal strength bars showing.
I don't know if this means that under Android 1.6 it is actually using
the phone data network for connectivity instead of the Wi-Fi
connectivity when both networks are available, or if the
getActiveNetworkInfo call is just returning the wrong information for
Android 1.6.
Has anyone else seen this issue with Andoid 1.6? It would be too bad
if 1.6 is really using the bandwidth on the phone data network instead
of the Wi-Fi network when both networks are present. Does anyone know
if there is a different way to correctly detect if the Android device
has Wi-Fi connectivity?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---