判断是否连接网络
发表于:2024-11-30 作者:热门IT资讯网编辑
编辑最后更新 2024年11月30日,public boolean isConnectingToInternet(){ConnectivityManager connectivity = (ConnectivityManager) con
public boolean isConnectingToInternet(){
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
return false;
}