GetNetworkInfo — Parameters, Returns, and Examples
What it is
GetNetworkInfo is a method-name used in multiple contexts (Android’s ConnectivityManager, embedded Wi-Fi libraries like ESP8266, and some RPC/node APIs). Below are concise, actionable summaries for the three most common meanings so you can pick the one you need.
1) Android (ConnectivityManager.getNetworkInfo)
- Where: android.net.ConnectivityManager (deprecated in newer APIs)
- Parameters:
- getNetworkInfo(int networkType) — an int specifying the network type (e.g., TYPE_WIFI, TYPE_MOBILE).
- getNetworkInfo(Network network) — an android.net.Network object specifying the network.
- Requires permission: ACCESS_NETWORKSTATE
- Returns: NetworkInfo (or null) — object describing connection state for the requested type or network.
- Notes: Deprecated (use getAllNetworks(), getNetworkCapabilities(), or registerNetworkCallback() in modern APIs). Does not support multiple networks of the same type.
- Example (Java, deprecated API):
java
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifiInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiInfo != null && wifiInfo.isConnected()) {// connected over Wi‑Fi }
2) ESP8266/Arduino WiFi.getNetworkInfo
- Where: ESP8266WiFi / Scan class (getNetworkInfo helper)
- Parameters:
Leave a Reply