【发布时间】:2018-07-16 01:46:13
【问题描述】:
加载应用程序时,ConnectivityManager 出现错误。我用过很多次,但这是我第一次遇到它。
它显示为 null,但我不知道这个错误是什么原因造成的。
这是我的代码:
final ConnectivityManager connMgr = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (wifi.isConnected()) {
baseUrl = URL1;
} else if (mobile.isConnected()) {
baseUrl = URL2;
}
这是Logcat上的错误
【问题讨论】:
-
我在该 logcat 屏幕截图中没有看到任何表明连接管理器为空的内容
-
它指出了
final ConnectivityManager connMgr = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); -
我更新了这个问题。我附上了截图
-
你在哪里使用那个代码?
-
在
OnCreateView
标签: android android-connectivitymanager