SoFunction
Updated on 2025-04-06

Check the change of network connection status in Android when there is no network.

Add a permission in the

<uses-permission android:name=".ACCESS_NETWORK_STATE" />
<intent-filter> 
  <action android:name=".CONNECTIVITY_CHANGE" />
</intent-filter>

Implemented in the main code:

@Override
protected void onCreate(Bundle savedInstanceState) {
  (savedInstanceState);
  setContentView(.activity_main);
  checkNetwork();
  if (!checkNetwork()) {
    (this, "No Internet", Toast.LENGTH_LONG).show();
    Intent intent = new Intent(".WIRELESS_SETTINGS");
    startActivity(intent);
    return;
  }
}
private boolean checkNetwork() {
  ConnectivityManager conn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo net = ();
  if (net != null &amp;&amp; ()) {
    return true;
  }
  return false;
}

The above is what the editor introduces to you. Check the changes in network connection status in Android. When there is no network, you will jump to the settings interface. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!