WiFiUtil,此工具类不是网上大家用烂的那一份,是博主亲自编写,亲自测试,代码简洁清晰,可满足日常开发。
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* Created on 2021/4/2 13:45
*
* @author Gong Youqiang
*/
public class WiFiUtil {
/**
* 判断是否连接WIFI
* @param context 上下文
* @return boolean
*/
public static boolean isWifiConnected(Context context) {
ConnectivityManager connectivityManager
= (ConnectivityManager) context.getSystemService(
Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_WIFI);
if (wifiNetworkInfo.isConnected()) {
return true;
}
return false;
}
}
网友评论