我正在使用以下功能检查网络连接,但交换 wifi 状态时应用程序崩溃
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connec = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connec.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected() == true) {
return true;
}
return false;
}