我需要检查Android应用上的Internet连接。在Android上检查Internet连接
我正在使用此代码:
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni!=null && ni.isAvailable() && ni.isConnected()) {
return true;
} else {
return false;
}
而且无法通过下一个错误:
The method getSystemService(String) is undefined for the type ConxsMTD
我尝试使用getContext().getSystemService
也失败,下一个错误:
The method getContext() is undefined for the type ConxsMTD
任何想法我做错了什么?
在这两种情况下,你使用的是不可用的方法在你使用它们的课堂上。这是基本的Java知识... – WarrenFaith 2013-03-25 18:52:04