Android WifiLock WIFI_MODE_SCAN_ONLY 不起作用

发布于 2024-12-12 08:00:23 字数 673 浏览 0 评论 0原文

我正在尝试阻止 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人事已非 2024-12-19 08:00:23

WifiLock 不适用于此。仅适用于“允许应用程序保持 Wi-Fi 无线电唤醒”。这并不禁止任何人连接到 wifi。只说“我希望至少能够在睡眠模式下执行此操作”。
你必须按照上面所说的Peanut进行操作:获取所有存储的网络的列表,然后在BroadcastReceiver中禁用wifi。

@Override
public void onReceive(Context c, Intent intent) {
    saveWifiList(mainWifi.getScanResults());

    unregisterReceiver(this);
    mainWifi.setWifiEnabled(false);

    showWifiList();     
}

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.

@Override
public void onReceive(Context c, Intent intent) {
    saveWifiList(mainWifi.getScanResults());

    unregisterReceiver(this);
    mainWifi.setWifiEnabled(false);

    showWifiList();     
}
聆听风音 2024-12-19 08:00:23

一种方法是获取所有存储的网络的列表,然后禁用它们。您可能希望将它们的状态存储在某个地方,以便在完成后可以恢复初始状态。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文