This code seems to return true unconditionally. Of course, I suppose
it could be the emulator, but here is the deal. When I switch my wi-
fi off and try using the emulator browser, I get the built-in Android
404 page. However, when my application tests for a net connection
using the code below, it returns true.
public boolean iCanHasDataNowKThxBye() {
ConnectivityManager connMgr=(ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info=connMgr.getActiveNetworkInfo();
return(info!=null && info.isConnected());
}
Scott
On Aug 21, 6:29 am, Mark Murphy <[email protected]> wrote:
> Guru wrote:
> > /**
> > * Checks whether the device is able to connect to the network
> > * @param context
> > * @return
> > */
> > public static boolean isNetworkAvailable(Context context) {
>
> > ConnectivityManager connectivity = (ConnectivityManager) context
> > .getSystemService(Context.CONNECTIVITY_SERVICE);
> > if (connectivity == null) {
> > Log.w("tag", "couldn't get connectivity manager");
>
> > } else {
> > NetworkInfo[] info = connectivity.getAllNetworkInfo();
>
> > if (info != null) {
>
> > for (int i = 0; i < info.length; i++) {
>
> > if (info[i].getState() == NetworkInfo.State.CONNECTED) {
>
> > return true;
>
> > }
>
> > }
>
> > }
> > }
> > return false;
> > }
>
> I have been using:
>
> ConnectivityManager
> connMgr=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
> NetworkInfo info=connMgr.getActiveNetworkInfo();
>
> return(info!=null && info.isConnected());
>
> Are there scenarios where a NetworkInfo other than
> getActiveNetworkInfo() might be connected?
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android Development Wiki:http://wiki.andmob.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---