Home > Tricks & Tips > Check network availability

Check network availability

It can be done like this:

    static class Utilities {
    	public static boolean checkNetworkAvailable(Context c) {
    		// get connection manager from system service
    		ConnectivityManager manager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    		// get network info status
    		NetworkInfo netInfo = manager.getActiveNetworkInfo();
    		// check availability status
    		if(netInfo != null && netInfo.isAvailable()) {
    			return true;
    		return false;

However, in order to make it work, you also need to set uses-permission.

Add this line to the AndroidManifest.xml

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

Hope you like it!


Pete Houston

  1. November 15, 2012 at 3:14 am

    fantastycznie imponujący

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: