Monday, March 26, 2012

How to check internet connection in Android

First In androidmanifest.xml file give the permission of internet given below. 
<uses-permission android:name="android.permission.INTERNET"></uses-permission> 
And Internet Connection code given below. This are simply create one Internetconnection() function. 

private boolean InternetConnection() {
ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
Toast.makeText(getApplicationContext(),"Please check your Internet connection, You are now seeing the cached version.",Toast.LENGTH_LONG).show();
return false;

1 comment:

  1. Found this new website. Really helpful for the aptitude preparation tests.Must see.!!!