NetTestUtil
public class NetTestUtil {
public static boolean netTest(Context context){
ConnectivityManager connectivityManager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if(connectivityManager==null){
Toast.makeText(context,"断网了,请连接网络后重试!",Toast.LENGTH_SHORT).show();
return false;
}
NetworkInfo netInfo=connectivityManager.getActiveNetworkInfo();
if(netInfo==null){
Toast.makeText(context,"断网了,请连接网络后重试!",Toast.LENGTH_SHORT).show();
return false;
}
if(netInfo.isConnected()){
return true;
}
return false;
}
}
网友评论