Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether Android is connected to WiFi or ethernet? [closed]

How to know whether I'm connected to WiFi or ethernet in Android? In Android OS this is notified for thess icons enter image description here

Does it exist a way to know it programmatically?

like image 602
Musculaa Avatar asked Mar 10 '14 14:03

Musculaa


People also ask

How can I tell if Im connected to Wi-Fi or Ethernet?

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.

How do I know if my Android phone is connected to Wi-Fi?

On the home screen, tap Apps > Settings. Under Network Connections, tap Wi-Fi; then tap the connected Wi-Fi network. Check the Signal strength.

How do you know if your phone is using Wi-Fi or data?

On Android phones: Go to Settings. Tap Connections. Then, tap Data Usage.


2 Answers

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.

like image 89
pchekuri Avatar answered Sep 21 '22 00:09

pchekuri


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()
like image 39
Kuffs Avatar answered Sep 20 '22 00:09

Kuffs