androidandroid-activitynetwork-state

Internet check connection not working android.net.isConected()


This question is related to how-do-you-check-the-internet-connection-in-android.

@William solution heelps me a lot, but on limited connection it`s not working.

I have connected to a wireless modem, but this modem is not connected to the internet.

According to the android docs this function should do all the work, but I think the data that is checked by function is only between android -> modem, and not android -> webservice (internet).

The @William code is:

final ConnectivityManager conMgr =  (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnected()) {
     //notify user you are online
} else {
     //notify user you are not online
} 

What can I do to check the internet conectivity? I missing something?


Solution

  • I think as an alternative you could make an actual HTTP request to a remote URL and see if it is successful.