Android WifiLock WIFI_MODE_SCAN_ONLY 不起作用
我正在尝试阻止 wifi 连接。我希望我的应用程序打开 wifi,但不连接到智能手机上已存储的任何网络。但即使在我使用 SCAN_ONLY 模式之后,他仍然继续连接到已经“知道”的网络。
.....
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
.....
wifiManager.setWifiEnabled(true);
WifiLock scanOnly = wifiManager.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "scanOnly");
scanOnly.acquire();
我已经绝望了,尝试断开连接以确保状态为 WIFI_STATE_ENABLED wifi。该应用程序在几秒钟内无法连接,但一段时间后它会以相同的方式连接到网络......
wifiManager.setWifiEnabled(true);
....
WHEN (WIFI STATE == WIFI_STATE_ENABLED)
{wifiManager.disconnect();
scanOnly.acquire();}
有人可以帮助我吗? 塔克斯
I'm trying to block the wifi connections. I want my application to turn on the wifi, but does not connect to any network that is already stored on the smartphone. But even after I use the SCAN_ONLY mode, he continues to connect to networks that already "know".
.....
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
.....
wifiManager.setWifiEnabled(true);
WifiLock scanOnly = wifiManager.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "scanOnly");
scanOnly.acquire();
Already in despair i tried to disconnect after to make sure that the state is WIFI_STATE_ENABLED wifi. That the app can not connect for a few seconds, but after some time it connects to a network in the same ...
wifiManager.setWifiEnabled(true);
....
WHEN (WIFI STATE == WIFI_STATE_ENABLED)
{wifiManager.disconnect();
scanOnly.acquire();}
Can someone help me?
Tks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WifiLock 不适用于此。仅适用于“允许应用程序保持 Wi-Fi 无线电唤醒”。这并不禁止任何人连接到 wifi。只说“我希望至少能够在睡眠模式下执行此操作”。
你必须按照上面所说的Peanut进行操作:获取所有存储的网络的列表,然后在BroadcastReceiver中禁用wifi。
WifiLock not for this. Only for "Allows an application to keep the Wi-Fi radio awake". This does not forbid anyone to connect to wifi. Only says "I want to be able to do at least this in sleep mode".
You have to do what you said Peanut above: get the list of all the stored networks and then disable wifi in BroadcastReceiver.
一种方法是获取所有存储的网络的列表,然后禁用它们。您可能希望将它们的状态存储在某个地方,以便在完成后可以恢复初始状态。
One way would be to get the list of all the stored networks and then disable them. You might want to store their state somewhere so you can restore the initial state after you're done.