【问题标题】:Determining the type and quality of the connectivity on Android确定 Android 上的连接类型和质量
【发布时间】:2014-10-03 11:30:38
【问题描述】:

我正在尝试了解如何使用 ConnectivityManager,虽然我在 HereHere 以及 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


【解决方案1】:

Call getActiveNetworkInfo() on ConnectivityManager。这将返回一个NetworkInfo 对象,它将告诉您type(WiFi、移动数据)、sub-typeroaming status

我唯一不确定的是 2G/3G/4G 的东西。我认为那是子类型,但我可能错了。

【讨论】:

  • 谢谢!!连同 2Dee 的链接,我设法破解了我需要的东西:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 1970-01-01
  • 2016-01-26
  • 1970-01-01
  • 2017-06-19
  • 1970-01-01
  • 2010-09-17
相关资源
最近更新 更多