直接给代码好啦,程序员都懂得!
if (!isConnectInternet(getContext())) {
Toast.makeText(getContext(), "暂时没有可用的网络,请检查网络", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), R.string.userorpass_wrong, Toast.LENGTH_LONG).show();
}
public boolean isConnectInternet(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null && activeNetInfo.isAvailable()) {
return true;
}else{
return false;
}
}