-1

I am making an android application. In this application i am receiving data from server. When Wi-Fi is enabled and internet connection is active in our device then it returns the number of record from the server but whenever wifi is enabled but inernet connection is not active or inactive then it gives the force close. I have already checked the wifi connection is enabled.

Please tell me this how can i check that internet is active in our device.

Thanks for advance

Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
user785696
  • 11
  • 1
  • This question has been asked over and over, see [here](http://stackoverflow.com/questions/1737877/how-to-determine-android-internet-connection) or [here](http://stackoverflow.com/questions/3211978/how-to-check-internet-connectivity-in-android) for example – THelper Jun 06 '11 at 10:48

1 Answers1

1

Try this code

 private boolean isNetworkAvailable() 
    {
        ConnectivityManager connectivityManager 
              = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null;
    }
David
  • 2,103
  • 3
  • 21
  • 29
  • i tried this code but it does not tell that in the device internet is active or not. Could plz tell me the internet connection active code. – user785696 Jun 06 '11 at 10:49
  • replace the last two lines with `if (connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting()) { // Device is online }` – THelper Jun 06 '11 at 10:56
  • @user785696 return value true means internet connection available,otherwise not – David Jun 06 '11 at 11:05
  • i have replaced the last two lines but it also prints the msg with true value. i have to check the internet connection in the device for active or not active – user785696 Jun 06 '11 at 13:34