编程技术 · 2022年6月27日

android 判断网络连接

我暂时是使用了Context对像的getSystemService来获取连接管理对像判断网络是否连接
public static boolean isNetworkAvaiable(Context pContext){
ConnectivityManager pCM = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if(pCM == null){
return true; //一律当联网处理
}else{
Network[] pNetworks= pCM.getAllNetworks();
if(pNetworks!=null && pNetworks.length>0){
return true;
}
return false;
}
}
使用时,传递一个Context对像,有更好方法的朋友,请告知更好的方法,谢谢
if(NetworkHelper.isNetworkAvaiable(pFragment.getContext())){

最新电影,电视剧,尽在午夜剧场

电影电视剧午夜不寂寞