How to know whether I'm connected to WiFi or ethernet in Android?
In Android OS this is notified for thess icons
Does it exist a way to know it programmatically?
Click the Start button, then click "Control Panel" and type "network status" in the search field at the top right of the window. Click "Network and Sharing" to see a readout of your current network status.
On the home screen, tap Apps > Settings. Under Network Connections, tap Wi-Fi; then tap the connected Wi-Fi network. Check the Signal strength.
On Android phones: Go to Settings. Tap Connections. Then, tap Data Usage.
http://developer.android.com/training/basics/network-ops/managing.html
ConnectivityManager cm = (ConnectivityManager) getActivity().
getSystemService(context.CONNECTIVITY_SERVICE);
And then you use:
cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_ETHERNET
or:
cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
to check whether it is on Wifi or Ethernet.
Hope that helped.
Is this enough?
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo Wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (Wifi.isConnected()) { return true; }
Also, to get wifi details:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getSSID()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With