【发布时间】:2014-10-03 11:30:38
【问题描述】:
我正在尝试了解如何使用 ConnectivityManager,虽然我在 Here 和 Here 以及 Official documentation 上看到了一些很好的示例。
我已经设置了 BroadcastReceiver 并监听了“android.net.conn.CONNECTIVITY_CHANGE”Intent,但我仍然对我应该如何弄清楚以下伪逻辑感到困惑:
String result = null;
if (WifiConnected)
result = "Wifi: " + getWifiName();//or ID that can be related to the list of Wifi networks on the device
else if (MobileDataConnected)
{
String networktype = GetMobileNetworkType();//2G/3G/4G
String roaming = IsMobileRoaming();//Roam/Home
result = "Mobile: " + networktype + " " + roaming;
}
else
{
result = "Not connected";
}
任何帮助将不胜感激,
谢谢。
【问题讨论】:
-
有人分享了一个很好的要点,可能对你有用:gist.github.com/emil2k/5130324
-
谢谢!!连同 CommonsWare 的回答,我设法破解了我需要的东西:-)
标签: android broadcastreceiver android-wifi connectivity