Code is needed: When a user presses a button, it checks whether it is connected to the Internet, if not - a message is displayed with two options: connect to the Internet (settings open) or exit the application.

  • one
    wifi connection does not guarantee internet accessibility. - ermak0ff

1 answer 1

Try this:

public boolean checkConnection() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); } 

Just do not forget to register in the manifest <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

This will determine the connection to the general Internet, and not just to wi-fi