+ Reply to Thread
Results 1 to 2 of 2

Thread: How to detect Internet States?

  1. #1
    Junior Member
    Join Date
    Aug 2012

    How to detect Internet States?

    I have developed an online examination app.It is working when they is internet connectivity but when internet is not connected it is showing some exception and application is force closed .I want to show user message which may be like "Internet is not available" or something like that when they is no internet connectivity.
    please let me know how to do that.

  2. #2
    All internet connection and states are handled by ConnectivityManager you can query it to know is internet connected or not check the utility function which returns boolean value true for internet connected and false for not connected.

    public boolean isConnectingToInternet(){
            ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
              if (connectivity != null)
                  NetworkInfo[] info = connectivity.getAllNetworkInfo();
                  if (info != null)
                      for (int i = 0; i < info.length; i++)
                          if (info[i].getState() == NetworkInfo.State.CONNECTED)
                              return true;
              return false;
    Note:Add INTERNET and ACCESS_NETWORK_STATE permissions in androidmanifest.xml

+ Reply to Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts