package com.common.lib_base.utils;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.provider.Settings;

/**
 * Date: 2022/5/19 0019 14:40
 * Description:
 */
public class NetworkUtils {

    /**
     * 判断是否打开网络
     *
     * @param context
     * @return
     */
    public static boolean isNetworkAvaiable(Context context) {
        boolean isAvaiable = false;
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()) {
            isAvaiable = true;
        }
        return isAvaiable;
    }


    /**
     * 跳转到网络设置页面
     * @param context
     */
    public static void goNetSettings(Context context) {
        Intent intent = null;
        //判断当前系统版本
        if (Build.VERSION.SDK_INT > 10) {
            intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
        } else {
            intent = new Intent();
            intent.setClassName("com.android.setting", "com.android.settings.WirelessSettings");
        }
        context.startActivity(intent);
    }

}
