How do you check if the android is connected to wifi?



  • We need the code: When the user presses the button, it is checked whether it is connected to the Internet, if not, with two options: it will be connected to the internet (the constructions open) or out of the annex.



  • Try this:

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

    Don't forget to write the manifest. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    It'll set up an Internet connection, not just a wi-fi.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2