当前位置: 代码迷 >> Android >> android 稽查 网络是否可用
  详细解决方案

android 稽查 网络是否可用

热度:271   发布时间:2016-05-01 12:00:08.0
android 检查 网络是否可用

/**

* 网络是否可用

*?

* @param context

* @return

*/

public static boolean isNetworkAvailable(Context context) {

ConnectivityManager mgr = (ConnectivityManager) context

.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo[] info = mgr.getAllNetworkInfo();

if (info != null) {

for (int i = 0; i < info.length; i++) {

if (info[i].getState() == NetworkInfo.State.CONNECTED) {

return true;

}

}

}

return false;

}

  相关解决方案