Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 检查wifi是否在android类中打开_Java_Android_Android Studio - Fatal编程技术网

Java 检查wifi是否在android类中打开

Java 检查wifi是否在android类中打开,java,android,android-studio,Java,Android,Android Studio,我有这门课: 导入android.content.Context; 导入android.net.wifi.WifiManager; 导入静态androidx.core.content.ContextCompat.getSystemService; 公共级Wifi{ 公共静态布尔值(){ WifiManager WifiManager=(WifiManager)getSystemService(Context.WIFI_服务); 返回wifiManager.isWifiEnabled(); }

我有这门课:

导入android.content.Context;
导入android.net.wifi.WifiManager;
导入静态androidx.core.content.ContextCompat.getSystemService;
公共级Wifi{
公共静态布尔值(){
WifiManager WifiManager=(WifiManager)getSystemService(Context.WIFI_服务);
返回wifiManager.isWifiEnabled();
}

}
改用.getApplicationContext().getSystemService

而不是确切的哪一部分?WifiManager WifiManager=(WifiManager)getSystemService(Context.WIFI_SERVICE);=>WifiManager WifiManager=(WifiManager)getApplicationContext().getSystemService(Context.WIFI_服务);您可以像下面这样重写代码:public static boolean isOn(Context Context){WifiManager WifiManager=(WifiManager)Context.getSystemService(Context.WIFI_SERVICE);返回WifiManager.isWifiEnabled();},但当您在片段/活动中使用它时,请像下面这样使用WIFI.isOn(getApplicationContext())