简体   繁体   English

Android Wear OS 关闭 Wifi

[英]Android Wear OS turn off Wifi

I want to turn off wifi for battery save on some screen where I don't need it.我想在不需要的某些屏幕上关闭 wifi 以节省电池电量。

I tried this:我试过这个:

WifiManager wifiManager = (WifiManager) SensorApplication.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null) wifiManager.setWifiEnabled(false);

That works fine to enable wifi.这可以很好地启用wifi。 To disable wifi it works but something like 2s later wifi automatically turns back on.要禁用 wifi,它可以工作,但 2 秒后 wifi 会自动重新打开。 I tried to look at the dev options if something can explain this but I disable all option.如果有什么可以解释的话,我尝试查看开发选项,但我禁用了所有选项。

If someone has an idea for explain why wifi automatically turn on when I turn off with this solution, or has another solution to disable wifi that would be great.如果有人有一个想法来解释为什么当我使用此解决方案关闭时 wifi 会自动打开,或者有另一种禁用 wifi 的解决方案,那就太好了。

Thanks in advance.提前致谢。

As per the documentation https://developer.android.com/reference/kotlin/android/net/wifi/WifiManager#setWifiEnabled(kotlin.Boolean) , setWifiEnabled() is deprecated.根据文档https://developer.android.com/reference/kotlin/android/net/wifi/WifiManager#setWifiEnabled(kotlin.Boolean) ,不推荐使用 setWifiEnabled() 。 Are you targeting Q?.你的目标是Q吗? Check the return value of this wifiManager.setWifiEnabled(false)检查这个wifiManager.setWifiEnabled(false)的返回值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM