Add this line to AndroidManifest.xml
Main.java
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Main.java
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isWifiConnected = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if (isWifiConnected) // true if wifi connected
editText.setText("Wifi is connected");
else
editText.setText("Wifi is NOT connected");
boolean isWifiConnected = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if (isWifiConnected) // true if wifi connected
editText.setText("Wifi is connected");
else
editText.setText("Wifi is NOT connected");
No comments:
Post a Comment