package com.example.androidinterviewjxd.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
public class NetworkUtils {
/**
* 判断当前网络是否连接
* @param context
* @return
*/
public static boolean isNetworkConnected(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network network = connectivityManager.getActiveNetwork();
NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);
return networkCapabilities!=null;
}
/**
* 判断当前的网络类型是wifi,流量还是有线网络
* @param context
* @return
*/
public static String getCurrentNetworkType(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager) contex
Android Q网络状态判断,亲测可用
最新推荐文章于 2024-05-16 03:27:12 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)