Android internet connectivity check problem

Posted by Chaoz on Stack Overflow See other posts from Stack Overflow or by Chaoz
Published on 2010-05-02T12:14:16Z Indexed on 2010/05/02 12:17 UTC
Read the original article Hit count: 229

Filed under:
|

Hello,

I'm new to Android development and working on an Android application that requires the phone to be connected to the internet, through either Wifi, EDGE or 3G.

This is the code that I'm using:

public static boolean isConnected()
{
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo().isConnectedOrConnecting();
}

I've also set these permissions in the manifest file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

This works fine in the emulator running version 1.5 of Android when 3G is enabled, but it crashes when I disable the 3G connection. My application throws a null pointer exception when I call isConnectedOrConnecting().

Hope that anyone knows the solution to this.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about android

Related posts about internet