【发布时间】:2013-05-05 02:00:11
【问题描述】:
我尝试在我的 SherlockFragment 中检查网络连接,但无法识别 getSystemService() 方法。
下面是我的代码(来自http://developer.android.com/training/basics/network-ops/connecting.html)
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
// fetch data
} else {
// display error
}
提前致谢
【问题讨论】:
标签: android android-networking