Android ::如何与WiFi网络断开连接? [英] Android :: How to disconnect from a wifi network?

查看:132
本文介绍了Android ::如何与WiFi网络断开连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google上搜索了很多网站,说禁用Wifi广播".但就我而言,我只想让android设备与特定的wifi网络(已知的SSID)断开连接,而无需关闭WiFi无线电.请给我一些有关此问题的见识

I have Googled and find many sites saying about 'disabling Wifi radio'. But in my case, I just want the android device to disconnect from a specific wifi network(SSID preknown) without switching OFF the WiFi radio. Please give me some insights on this issue

推荐答案

哇,这本不需要花一个月的时间来回答.

Wow this shouldn't have taken a month to be answered.

这是我通常使用的最简单的方法:

Here's the easiest way that I usually use:

 WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
 wifi.disconnect();
 discon = new DisconnectWifi();
 registerReceiver(discon, new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION));

DisconnectWifi只是广播广播接收器的一小类:

Where DisconnectWifi is just a small class the extends BroadcastReceiver:

  public class DisconnectWifi extends BroadcastReceiver  {

    @Override
    public void onReceive(Context c, Intent intent) {
        if(!intent.getParcelableExtra(wifi.EXTRA_NEW_STATE).toString().equals(SupplicantState.SCANNING)) wifi.disconnect();
        }
    }

这篇关于Android ::如何与WiFi网络断开连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆