Click here to Skip to main content
13,763,464 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


157 bookmarked
Posted 30 Dec 2012
Licenced CPOL

Check whether network is available on Android phone

, 30 Dec 2012
Rate this:
Please Sign up or sign in to vote.
This code snippet checks whether network is available on an Android phone.


In some Android applications, they can be run properly once the network on device is enable. Or, Android developers want to check the network status before proceed. The simple code snippet I will show today is so simple but sometime it will take you a little bit of time to find/research. 

This routine was run and tested as well on Android 2.2 (API 8) 

Using the code

 * Checks whether the network is available on Android device.
 * If the network signal is very low, it will be evaluated as NOT available.
 * This routine will check both MOBILE and WIFI signal.
 * If both of them are in disable status, <code>false</code> will be return absolutely.
 * </p>
 * Return <code>true</code> if the network is available. Otherwise, return <code>false</code>.
 * </p>
 * @param ctx Context.
 * @return <code>True</code> : the network is available.</br>
 *         <code>False</code>: the network is NOT available.
 public static boolean isNetworkAvailable(Context ctx) {
	ConnectivityManager connMgr = (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
	if(connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected() ||
			return true;
	return false;


First release on Dec 30, 2012.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

QuestionNcie Pin
Real Hyder3-Oct-13 3:12
memberReal Hyder3-Oct-13 3:12 
GeneralMy vote of 4 Pin
GOLDENPrinciple11-Sep-13 6:45
memberGOLDENPrinciple11-Sep-13 6:45 
Questionwifi problem Pin
dzyssssss22-Aug-13 16:32
memberdzyssssss22-Aug-13 16:32 
SuggestionRequiers permission Pin
Member 1006643320-May-13 20:41
memberMember 1006643320-May-13 20:41 
GeneralMy vote of 5 Pin
Phat (Phillip) H. VU6-Apr-13 23:29
memberPhat (Phillip) H. VU6-Apr-13 23:29 
GeneralHelpful Pin
Gremz21-Feb-13 16:02
memberGremz21-Feb-13 16:02 
GeneralMy vote of 5 Pin
WhiteOsoBDN19-Feb-13 0:45
memberWhiteOsoBDN19-Feb-13 0:45 
GeneralMy vote of 5 Pin
Bandi Ramesh16-Feb-13 0:52
memberBandi Ramesh16-Feb-13 0:52 
GeneralMy vote of 5 Pin
kksrinivasan8922-Jan-13 20:34
memberkksrinivasan8922-Jan-13 20:34 
GeneralMy vote of 5 Pin
uyentran311@yahoo.com10-Jan-13 15:47
memberuyentran311@yahoo.com10-Jan-13 15:47 
GeneralRe: My vote of 5 Pin
10-Jan-13 15:55
suss10-Jan-13 15:55 
Thanks for your vote.
GeneralMy vote of 5 Pin
Thong Nguyen883-Jan-13 15:15
memberThong Nguyen883-Jan-13 15:15 
GeneralRe: My vote of 5 Pin
10-Jan-13 15:55
suss10-Jan-13 15:55 
GeneralMy vote of 5 Pin
Member 97262843-Jan-13 4:55
memberMember 97262843-Jan-13 4:55 
GeneralRe: My vote of 5 Pin
10-Jan-13 15:56
suss10-Jan-13 15:56 
GeneralMy vote of 5 Pin
30-Dec-12 4:17
suss30-Dec-12 4:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06-2016 | 2.8.181112.3 | Last Updated 30 Dec 2012
Article Copyright 2012 by Retired Author
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid