首页 > 其他分享 >Android wifi主要广播详解

Android wifi主要广播详解

时间:2024-08-29 15:55:29浏览次数:11  
标签:java wifi 28 MainActivity 详解 onReceive 3984 Android

Android wifi相关主要广播总结

文章目录

一、前言

wifi应用开发肯定会用到wifi开关和wifi连接状态监听的广播,有些广播比较容易混淆,本文进行详细总结。

比如wifi网络变化广播:CONNECTIVITY_ACTION、WIFI_STATE_CHANGED_ACTION、NETWORK_STATE_CHANGED_ACTION 这三个比较容易搞混。

SUPPLICANT_STATE_CHANGED_ACTION 和 SUPPLICANT_CONNECTION_CHANGE_ACTION 比较容易搞混。

很多wifi相关开发的人,搞了多年还是没有对wifi主要广播进行过梳理总结。

本文对各个广播使用情况进行详细介绍,有需要的可以看看。

本文不仅仅对wifi相关广播做了介绍,还展示了具体情况下的打印日志,
后续还对广播携带数据的查找方式进行了介绍,有一定的研究学习价值,可以收藏学习。

二、wifi主要广播分析介绍

1、简单的广播监听

//注册
IntentFilter mFilter = new IntentFilter();
mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); //网络变化广播,一般是ip地址变化
mFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); //wifi开关变化广播
mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); //wifi连接变化广播
mFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);//wifi信息验证变化广播
mFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);//wifi开关变化
mFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);//扫描到wifi广播
registerReceiver(mReceiver, mFilter, Context.RECEIVER_EXPORTED); //Android14 普通应用要多加一个参数,否则报异常。

//监听
    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            LogUtil.debug("action = " + action);

        }
    };
//反注册
unregisterReceiver(mReceiver1);

上面的代码只是简单监听action日志,未获取action相关的具体信息。
上面是Wifi相关的常用广播广播,还有些不常用的广播。最后介绍一下。

2、wifi 广播对应的 action 字符串:

//网络变化广播
ConnectivityManager.CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";

WifiManager.java:
//wifi 开关状态变化广播
String WIFI_STATE_CHANGED_ACTION ="android.net.wifi.WIFI_STATE_CHANGED";
//wifi 连接状态变化广播
String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";
//wifi 连接验证状态变化广播 2
String SUPPLICANT_STATE_CHANGED_ACTION ="android.net.wifi.supplicant.STATE_CHANGE";
//wifi 开关状态变化广播2
String SUPPLICANT_CONNECTION_CHANGE_ACTION="android.net.wifi.supplicant.CONNECTION_CHANGE";
//扫描到wifi广播
String SCAN_RESULTS_AVAILABLE_ACTION = "android.net.wifi.SCAN_RESULTS";

可以看到action中 WIFI_STATE_CHANGED 是Wifi开关广播,STATE_CHANGE是Wifi网络变化广播;
可以看到supplicant相关的action中 WIFI_STATE_CHANGE 是Wifi状态改变广播,CONNECTION_CHANGE是Wifi开关状态变化广播;

supplicant 的理解,有些人说是硬件/底层相关的广播,其实不是的。这个只是Wifi不同状态的广播。
supplicant 翻译过来 表示: 请求者。其实就是网络校验相关的广播。开关也有相关校验吧。

所以wifi开关和wifi断开连接都有supplicant相关日志。
但是很多情况其实是不需要 supplicant 广播监听的,但是有些情况可以使用这个广播,
往下看看具体日志,就知道这个 supplicant 的用途了。

3、广播和接收的相关数据

    //监听
    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            LogUtil.inform("action = " + action);
            switch (action) {
                case ConnectivityManager.CONNECTIVITY_ACTION: //网络变化广播,一般是ip地址变化
                    String wifiIp = FunctionUtil.getNetIpAddress("wlan0");
                    LogUtil.inform("wifiIp = " + wifiIp);
                    break;
                case WifiManager.WIFI_STATE_CHANGED_ACTION: //wifi开关变化广播
                    int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
                    LogUtil.inform("wifiState = " + wifiState + " (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)");
                    break;
                case WifiManager.NETWORK_STATE_CHANGED_ACTION: //wifi连接变化广播,断开或者断开某个wifi
                    NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                    LogUtil.inform("info = " + info);
                    break;
                case WifiManager.SUPPLICANT_STATE_CHANGED_ACTION: //wifi信息验证变化广播
                    NetworkInfo.DetailedState detailedState = WifiInfo.getDetailedStateOf((SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE));
                    LogUtil.inform("detailedState = " + detailedState);
                    int error = intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, -1);
                    LogUtil.inform("error = " + error);
                    if (error == WifiManager.ERROR_AUTHENTICATING) { // 1 密码错误
                    }
                    break;
                case WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION: //wifi开关变化,已经废弃
                    boolean isWifiOn = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false);
                    LogUtil.inform("isWifiOn = " + isWifiOn);
                    break;
                case WifiManager.SCAN_RESULTS_AVAILABLE_ACTION: //扫描到wifi广播
                    //是否扫描成功
                   boolean lastScanSucceeded = intent.getBooleanExtra(WifiManager.EXTRA_RESULTS_UPDATED, true);
                   LogUtil.inform("lastScanSucceeded = " + lastScanSucceeded); //基本都返回true
                    List<ScanResult> scanResults = mWifiManager.getScanResults(); //需要动态权限:ACCESS_FINE_LOCATION
                    LogUtil.inform("scanResults size = " + scanResults.size());

                    break;
            }

        }
    };

上面是wifi常用广播添加接收 额外数据Extra的代码。
关于这些Action 有什么 Extra数据,后面有介绍。
具体日志打印情况,可以继续往下看。

三、广播相关日志:

下面是上面广播接收后具体的日志打印,有兴趣的可以细细看一下,肯定是会有收获的。

1、wifi扫描广播的日志

只要界面注册监听了这个wifi扫描广播,就会收到这个广播消息。

MainActivity.java(45)::onReceive - action = android.net.wifi.SCAN_RESULTS
MainActivity.java(74)::onReceive - lastScanSucceeded = true
MainActivity.java(76)::onReceive - scanResults size = 52

MainActivity.java(45)::onReceive - action = android.net.wifi.SCAN_RESULTS
2MainActivity.java(74)::onReceive - lastScanSucceeded = true
MainActivity.java(76)::onReceive - scanResults size = 53

MainActivity.java(45)::onReceive - action = android.net.wifi.SCAN_RESULTS
MainActivity.java(74)::onReceive - lastScanSucceeded = true
MainActivity.java(76)::onReceive - scanResults size = 57

wifi扫描的广播是每十秒一次扫描触发。

如果要获取到扫描的wifi列表,需要应用获取到动态权限:ACCESS_FINE_LOCATION

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

可以在代码中动态申请,也可以在原生设置应用中打开这个应用的信息手动允许这个权限。

下面的日志是保留了时间戳的日志。

后面日志比较多,详细看一两个就行,其他的都是类似的。

2、wifi连接、断开的日志

(1)第一次连接的日志
①密码正确情况的日志
1、wifi连接变化广播,CONNECTING状态,连接中
08-28 02:49:25.033  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 02:49:25.035  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

2、wifi连接变化广播 supplicant,CONNECTING状态,多次
08-28 02:49:25.039  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 02:49:25.040  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 02:49:25.041  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
...

3、wifi连接变化广播,CONNECTING/AUTHENTICATING状态,连接中+验证中
08-28 02:49:25.416  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 02:49:25.417  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/AUTHENTICATING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

4、wifi连接变化广播 supplicant,AUTHENTICATING 状态,验证中
08-28 02:49:25.419  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 02:49:25.419  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 02:49:25.420  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

5、wifi连接变化广播 supplicant,CONNECTING状态
08-28 02:49:25.445  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 02:49:25.446  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

6、wifi连接变化广播,CONNECTING/OBTAINING_IPADDR 状态,请求分配ip
08-28 02:49:25.454  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 02:49:25.455  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

7、wifi连接变化广播,CONNECTING/OBTAINING_IPADDR 状态,请求分配ip
08-28 02:49:25.475  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 02:49:25.476  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = OBTAINING_IPADDR
08-28 02:49:25.476  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

8、wifi连接变化广播,CONNECTING/OBTAINING_IPADDR 状态,请求分配ip,估计是ip分配完成
08-28 02:49:26.095  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 02:49:26.096  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

9、wifi连接变化广播,CONNECTED 状态,已连接状态
08-28 02:49:26.135  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 02:49:26.138  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

10、网络变化广播,ip变化
08-28 02:49:26.312  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 02:49:26.323  8820  8820 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = 192.5.1.8

从上面日志可以看到比较详细的wifi连接完成过程:

wifi连接过程的广播:连接中-->校验密码-->分配ip-->连接完成 --> ip 变化

密码正确的wifi连接过程中,在 wifi.STATE_CHANGE 广播已经包含了 supplicant广播内容。
并且 supplicant广播内容没有包含wifi连接完成的广播,只是一些校验过程的广播;
总的来说,wifi.STATE_CHANGE 广播 包含的状态比较全面,从开始到完成的。

最后的网络变化广播,不是没啥action,是调用系统api获取了wifi的ip地址。

②密码错误情况的日志
1、wifi连接变化广播,DISCONNECTED/SCANNING 状态,断开
08-28 03:26:37.559  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:26:37.561  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: DISCONNECTED/SCANNING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

2、wifi连接变化广播 supplicant,SCANNING 状态
08-28 03:26:37.563  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:26:37.564  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = SCANNING
08-28 03:26:37.565  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = 1 //返回密码错误的情况

3、wifi连接变化广播,CONNECTING状态,连接中不验证
08-28 03:26:40.297  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:26:40.300  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

4、wifi连接变化广播 supplicant,CONNECTING 状态,多次
08-28 03:26:40.300  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:26:40.301  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 03:26:40.301  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

08-28 03:26:40.505  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:26:40.506  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 03:26:40.506  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

08-28 03:26:40.532  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:26:40.534  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 03:26:40.535  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

5、wifi连接变化广播,CONNECTING/AUTHENTICATING 状态,连接中+验证中
08-28 03:26:40.563  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:26:40.564  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/AUTHENTICATING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

6、wifi连接变化广播 supplicant,AUTHENTICATING 状态,验证中
08-28 03:26:40.573  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:26:40.573  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 03:26:40.574  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

7、wifi连接变化广播,DISCONNECTED 状态,断开
08-28 03:26:44.758  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:26:44.759  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: DISCONNECTED/DISCONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

8、wifi连接变化广播 supplicant,DISCONNECTED 状态,断开
08-28 03:26:44.770  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:26:44.771  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = DISCONNECTED
08-28 03:26:44.771  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = 1  //返回密码错误的情况


08-28 03:26:47.604  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.SCAN_RESULTS

从上面日志可以看到比较详细的wifi密码错误连接完成过程:

wifi密码错误连接过程的广播:断开连接+扫描,密码错误-->连接中-->校验密码-->断开连接,密码错误

密码错误的wifi连接过程中,supplicant 广播内容可以判断出wifi 密码错误的情况;
之前我发现这个wifi连接状态的 supplicant 广播,怎么有两次密码错误的,
所以一直没有这个广播判断密码错误的情况,使用的是原生系统Setings的不断判断连接状态的方法。

现在看来是可以用这个wifi连接状态的 supplicant 广播,判断密码错误的,加上 detailedState 的判断就可以了;
最好是判断 detailedState = DISCONNECTED 的情况,因为这个时候已经是完成了整个校验过程。

所以说查看详细日志还是有作用的。

③ 无密码情况的连接
1、wifi连接变化广播,CONNECTING状态,连接中
08-28 06:16:33.045  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:16:33.047  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

2、wifi连接变化广播 supplicant,CONNECTING状态,多次(3次)
08-28 06:16:33.055  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:16:33.057  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:16:33.057  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 06:16:33.584  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:16:33.585  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:16:33.585  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 06:16:33.626  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:16:33.627  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:16:33.627  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

3、wifi连接变化广播,CONNECTING/OBTAINING_IPADDR 状态,连接中+请求ip分配
08-28 06:16:33.640  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:16:33.642  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

4、wifi连接变化广播 supplicant,OBTAINING_IPADDR 状态,请求ip分配
08-28 06:16:33.668  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:16:33.669  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = OBTAINING_IPADDR
08-28 06:16:33.669  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

5、wifi连接变化广播,CONNECTING/OBTAINING_IPADDR 状态,连接中+请求ip分配,应该是ip分配完成
08-28 06:16:33.790  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:16:33.791  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

6、wifi连接变化广播,CONNECTED 状态,已连接状态
08-28 06:16:33.828  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:16:33.833  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

7、网络变化广播,ip变化
08-28 06:16:34.032  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 06:16:34.054  3984  3984 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = 192.168.31.47

可以看到,和有密码的wifi连接的广播是差不多的,但是没有验证过程的广播 CONNECTING/AUTHENTICATING;
估计是不用验证密码所以跳过了 AUTHENTICATING 的过程。
过程:

wifi无密码连接过程的广播:连接中-->分配ip-->连接完成 --> ip 变化
(2)保存状态连接的日志
1、wifi连接变化广播,CONNECTING状态,连接中
08-28 03:40:55.506  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:40:55.507  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

2、wifi连接变化广播 supplicant,CONNECTING状态,多次(3次)
08-28 03:40:55.510  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:40:55.511  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 03:40:55.512  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 03:40:55.570  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:40:55.571  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 03:40:55.571  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 03:40:55.645  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:40:55.646  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 03:40:55.646  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

3、wifi连接变化广播,CONNECTING/AUTHENTICATING状态,连接中+验证中
08-28 03:40:55.745  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:40:55.746  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/AUTHENTICATING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

4、wifi连接变化广播 supplicant,AUTHENTICATING 状态,多次
08-28 03:40:55.747  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:40:55.748  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 03:40:55.748  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 03:40:55.769  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:40:55.770  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 03:40:55.770  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

5、wifi连接变化广播 ,CONNECTING 状态,
08-28 03:40:55.776  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:40:55.777  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

6、wifi连接变化广播 ,CONNECTING/OBTAINING_IPADDR 状态,请求分配ip
08-28 03:40:55.783  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:40:55.783  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

7、wifi连接变化广播 supplicant,OBTAINING_IPADDR 状态,请求分配ip
08-28 03:40:55.792  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:40:55.793  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = OBTAINING_IPADDR
08-28 03:40:55.793  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

8、wifi连接变化广播 ,CONNECTING/OBTAINING_IPADDR 状态,请求分配ip完成
08-28 03:40:55.875  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:40:55.876  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

9、wifi连接变化广播 ,CONNECTED 状态,完成连接
08-28 03:40:55.907  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:40:55.913  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

10、网络变化广播,ip变化
08-28 03:40:56.055  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 03:40:56.059  8820  8820 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = 192.168.31.79

可以看到连接已保存的wifi和第一次连接wifi过程基本是一样的。

过程:

连接保存的wifi过程的广播:连接中-->校验密码-->分配ip-->连接完成 --> ip 变化

后续有测试保存的wifi,修改密码后,再选择连接,这种情况和连接错误密码的wifi情况是差不多的,也是有wifi密码错误广播的。

(3)断开连接的wifi 的日志
1、wifi连接变化广播,DISCONNECTED 状态,断开
08-28 06:48:29.778  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:48:29.780  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: DISCONNECTED/DISCONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

2、wifi连接变化广播 supplicant,DISCONNECTED 状态,断开
08-28 06:48:29.785  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:48:29.786  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = DISCONNECTED
08-28 06:48:29.786  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

3、网络变化广播,ip变化
08-28 06:48:29.787  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 06:48:29.790  3984  3984 I WifiReceiverDemo: FunctionUtil.java(128)::getNetIpAddress - hardWareAddress = null
08-28 06:48:29.790  3984  3984 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = null

可以看到wifi断开的过程比较简单,断开后是没有wifi ip的。

过程:

断开wifi过程的广播:断开wifi--> ip 变化

并且可以看到断开wifi不会像连接wifi那样磨磨唧唧,没有断开中的状态,直接就是断开。
只有打开、关闭、连接wifi 有进行中的状态,断开wifi是没有进行中状态的。

(4)忘记连接的wifi的日志
1、wifi连接变化广播,DISCONNECTED 状态,断开
08-28 03:42:25.246  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 03:42:25.247  8820  8820 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: DISCONNECTED/DISCONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

2、wifi连接变化广播 supplicant,DISCONNECTED 状态,断开
08-28 03:42:25.259  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 03:42:25.260  8820  8820 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = DISCONNECTED
08-28 03:42:25.260  8820  8820 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

3、网络变化广播,ip变化
08-28 03:42:25.382  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 03:42:25.385  8820  8820 I WifiReceiverDemo: FunctionUtil.java(128)::getNetIpAddress - hardWareAddress = null
08-28 03:42:25.385  8820  8820 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = null

可以看到忘记wifi的关闭和断开wifi的广播情况是一样的。

过程:

忘记wifi过程的广播:断开wifi--> ip 变化
(5)已连接一个wifi的情况连接另外一个wifi的日志
1、wifi连接变化广播,DISCONNECTED 状态,断开
08-28 06:29:15.242  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:29:15.244  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: DISCONNECTED/DISCONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

2、wifi连接变化广播 supplicant,DISCONNECTED 状态,断开
08-28 06:29:15.264  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:29:15.265  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = DISCONNECTED
08-28 06:29:15.265  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

3、wifi连接变化广播,CONNECTING 状态,连接中
08-28 06:29:15.268  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:29:15.269  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

4、wifi连接变化广播 supplicant,CONNECTING 状态,连接中,多次(三次)
08-28 06:29:15.269  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:29:15.270  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:29:15.271  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

5、网络变化广播,ip变化
08-28 06:29:15.340  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 06:29:15.344  3984  3984 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = null

wifi连接变化广播 supplicant,CONNECTING 状态
08-28 06:29:15.371  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:29:15.372  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:29:15.373  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 06:29:15.420  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:29:15.421  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:29:15.422  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

6、wifi连接变化广播,CONNECTING/AUTHENTICATING 状态,验证中
08-28 06:29:15.433  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:29:15.434  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/AUTHENTICATING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

6、wifi连接变化广播 supplicant,AUTHENTICATING 状态,验证中,多次
08-28 06:29:15.440  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:29:15.441  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 06:29:15.441  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

08-28 06:29:15.451  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:29:15.452  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 06:29:15.452  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

7、wifi连接变化广播,CONNECTING 状态,连接中
08-28 06:29:15.506  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:29:15.507  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

8、wifi连接变化广播,CONNECTING/OBTAINING_IPADDR 状态,连接中+请求ip分配
08-28 06:29:15.513  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:29:15.514  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

9、wifi连接变化广播 supplicant,OBTAINING_IPADDR 状态,请求ip分配
08-28 06:29:15.523  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:29:15.524  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = OBTAINING_IPADDR
08-28 06:29:15.524  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

10、wifi连接变化广播,CONNECTING/OBTAINING_IPADDR 状态,ip分配完成
08-28 06:29:16.212  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:29:16.213  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

11、wifi连接变化广播,CONNECTED 状态,连接完成
08-28 06:29:16.233  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:29:16.234  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

12、网络变化广播,ip变化
08-28 06:29:16.401  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 06:29:16.404  3984  3984 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = 192.168.1.39

从上面广播可以看出,已连接wifi的情况连接另外一个wifi的过程,比普通连接的wifi:

(1)多了断开wifi的;
(2)过程中间也会收到 ip变化的广播。

过程:

连接第二个wifi过程的广播:断开wifi--> ip 变化 --> 连接中 --> 校验密码-->分配ip-->连接完成 --> ip 变化

3、wifi打开、关闭的日志

(1)wifi打开但是未连接wifi的日志:

​ 这个情况是打开wifi之前没有保存的wifi情况。

1、wifi开关变化广播,ENABLING 状态,正在打开
08-28 06:35:44.779  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 06:35:44.780  3984  3984 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 2 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

2、wifi开关变化广播,ENABLED 状态,已经打开
08-28 06:35:44.918  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 06:35:44.920  3984  3984 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 3 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

3、wifi开关变化广播 supplicant,ENABLED 状态,已经打开
08-28 06:35:44.932  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.CONNECTION_CHANGE
08-28 06:35:44.932  3984  3984 I WifiReceiverDemo: MainActivity.java(69)::onReceive - isWifiOn = true

上面的广播可以看出,wifi打开的日志中 wifi.WIFI_STATE_CHANGED 和 supplicant.CONNECTION_CHANGE 效果是一样的。
wifi.WIFI_STATE_CHANGED 的过程相对来说详细一点。

(2)wifi打开后自动连接上wifi的日志:

​ 这个情况是打开wifi前有已保存的wifi情况。

1、wifi开关变化广播,ENABLING 状态,正在打开
08-28 06:34:10.886  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 06:34:10.887  3984  3984 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 2 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

2、wifi开关变化广播,ENABLED 状态,已经打开
08-28 06:34:11.037  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 06:34:11.038  3984  3984 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 3 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

3、wifi网络变化广播 supplicant,ENABLED 状态,已经打开
08-28 06:34:11.047  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.CONNECTION_CHANGE
08-28 06:34:11.048  3984  3984 I WifiReceiverDemo: MainActivity.java(69)::onReceive - isWifiOn = true

//上面三个广播信息和上面打开wifi后未自动连接wifi是一样的。
08-28 06:34:13.673  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.SCAN_RESULTS

4、wifi连接变化广播 ,CONNECTING 状态,正在连接
08-28 06:34:13.723  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:34:13.724  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

5、wifi连接变化广播 supplicant,CONNECTING 状态,正在连接,多次
08-28 06:34:13.727  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:34:13.727  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:34:13.728  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 06:34:13.745  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:34:13.746  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:34:13.747  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 06:34:13.766  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:34:13.767  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = CONNECTING
08-28 06:34:13.767  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

6、wifi连接变化广播 ,CONNECTING/AUTHENTICATING 状态,验证密码
08-28 06:34:13.771  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:34:13.779  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/AUTHENTICATING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

7、wifi连接变化广播 supplicant,AUTHENTICATING 状态,验证密码
08-28 06:34:13.780  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:34:13.781  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 06:34:13.783  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1
08-28 06:34:13.783  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:34:13.784  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = AUTHENTICATING
08-28 06:34:13.784  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

8、wifi连接变化广播 ,CONNECTING 状态,正在连接
08-28 06:34:13.791  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:34:13.792  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/CONNECTING, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

9、wifi连接变化广播 ,CONNECTING/OBTAINING_IPADDR 状态,正在连接+请求分配ip
08-28 06:34:13.796  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:34:13.797  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

10、wifi连接变化广播 supplicant,OBTAINING_IPADDR 状态,请求分配ip
08-28 06:34:13.808  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:34:13.809  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = OBTAINING_IPADDR
08-28 06:34:13.812  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

11、wifi连接变化广播 ,CONNECTING/OBTAINING_IPADDR 状态,请求分配ip 完成
08-28 06:34:13.998  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:34:13.999  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTING/OBTAINING_IPADDR, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

12、wifi连接变化广播 ,CONNECTED 状态,连接完成
08-28 06:34:14.030  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:34:14.031  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

13、网络变化广播,ip变化
08-28 06:34:14.218  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 06:34:14.221  3984  3984 I WifiReceiverDemo: FunctionUtil.java(115)::getNetIpAddress - iF.getName() = wlan0 , ipAddress = 192.168.1.39
08-28 06:34:14.237  3984  3984 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = 192.168.1.39

上面日志可以看到,wifi打开后自动连接上wifi的情况,其实就是wifi单独打开的日志 加上 wifi单独连接上的日志情况。
过程:

打开并连接上wifi过程的广播:wifi正在打开--> wifi已打开 --> 连接中 --> 校验密码-->分配ip-->连接完成 --> ip 变化
(3)wifi未连接情况下关闭日志:
1、wifi开关变化广播,DISABLING 状态,正在关闭
08-28 03:45:02.249  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 03:45:02.250  8820  8820 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 0 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

wifi开关变化广播,DISABLING 状态,正在关闭
08-28 03:45:02.259  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 03:45:02.259  8820  8820 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 0 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

2、wifi开关变化广播,DISABLED 状态,完成关闭
08-28 03:45:02.347  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 03:45:02.348  8820  8820 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 1 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

3、wifi开关变化广播 supplicant,DISABLED 状态,完成关闭
08-28 03:45:02.366  8820  8820 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.CONNECTION_CHANGE
08-28 03:45:02.366  8820  8820 I WifiReceiverDemo: MainActivity.java(69)::onReceive - isWifiOn = false

上面的广播可以看出,wifi关闭的日志中 wifi.WIFI_STATE_CHANGED 和 supplicant.CONNECTION_CHANGE 效果是一样的。
wifi.WIFI_STATE_CHANGED 广播的过程相对来说详细一点。

过程:

关闭未连接的wifi过程的广播:wifi正在关闭--> wifi已关闭
(4)wifi已连接情况下关闭wifi 的日志:
1、wifi开关变化广播,DISABLING 状态,正在关闭
08-28 06:31:24.935  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 06:31:24.936  3984  3984 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 0 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

wifi开关变化广播,DISABLING 状态,正在关闭
08-28 06:31:24.944  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 06:31:24.944  3984  3984 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 0 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

2、wifi状态变化广播,DISCONNECTED 状态,断开
8-28 06:31:25.163  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.STATE_CHANGE
08-28 06:31:25.165  3984  3984 I WifiReceiverDemo: MainActivity.java(57)::onReceive - info = [type: WIFI[], state: DISCONNECTED/DISCONNECTED, reason: (unspecified), extra: (none), failover: false, available: false, roaming: false]

3、wifi状态变化广播 supplicant,DISCONNECTED 状态,断开
08-28 06:31:25.175  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.STATE_CHANGE
08-28 06:31:25.176  3984  3984 I WifiReceiverDemo: MainActivity.java(61)::onReceive - detailedState = DISCONNECTED
08-28 06:31:25.177  3984  3984 I WifiReceiverDemo: MainActivity.java(63)::onReceive - error = -1

4、wifi开关变化广播,DISABLED 状态,完成关闭
08-28 06:31:25.182  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.WIFI_STATE_CHANGED
08-28 06:31:25.182  3984  3984 I WifiReceiverDemo: MainActivity.java(53)::onReceive - wifiState = 1 (ex: 0=DISABLING, 1=DISABLED, 2=ENABLING, 3=ENABLED)

5、网络变化广播,ip变化
08-28 06:31:25.258  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.conn.CONNECTIVITY_CHANGE
08-28 06:31:25.263  3984  3984 I WifiReceiverDemo: MainActivity.java(49)::onReceive - wifiIp = null

4、wifi开关变化广播 supplicant,完成关闭
08-28 06:31:25.269  3984  3984 I WifiReceiverDemo: MainActivity.java(45)::onReceive - action = android.net.wifi.supplicant.CONNECTION_CHANGE
08-28 06:31:25.270  3984  3984 I WifiReceiverDemo: MainActivity.java(69)::onReceive - isWifiOn = false

从上面广播日志可以看到关闭WiFi的时候会,断开WiFi,还会有网络ip变化广播,之后是关闭完成广播。

过程:

关闭已连接的wifi过程的广播:wifi正在关闭--> 断开wifi网络 -->wifi已关闭 -->ip变化

上面这些广播日志对于大部分人没啥用,但是对于研究wifi连接过程是比较用作用的,很有参考价值。

根据项目需求,可以在对应的广播时间判断一些逻辑,比如wifi打开状态等,wifi连接状态,wifi密码验证情况等等。
广播的过程不仅仅是可以监听action 的Extra数据,还可以通过系统api,获取当前wifi或者ip情况进行确认。

四、其他

1、wifi常用广播小结

(1)wifi连接过程的广播:连接中-->校验密码-->分配ip-->连接完成 --> ip 变化
wifi断开、wifi开关的过程都比较简单,没啥好说的
(2)连接上wifi或者断开wifi都会有ip变化的广播
(3)wifi 打开和关闭状态的广播中,supplicant相关状态的广播没啥使用价值。
(4)wifi 连接状态的广播中,supplicant 状态的广播对于判断密码错误是有价值的。
(5)supplicant相关的广播毕竟是过时的广播,如果没有判断密码错误情况,就不要用supplicant相关的广播了

值得注意的是,连接上wifi后ip变化的时候马上获取ip,有出现过,获取到ip未空的情况;
规避这个问题可以可以通过WifiManager获取当前连接的wifi信息获取ip;(这个需要系统权限);
规避这个问题还可以延长一秒再获取ip。

最后再看一下本文开始说的容易混淆的几个广播和对应含义:

CONNECTIVITY_ACTION:网络ip变化广播
WIFI_STATE_CHANGED_ACTION :wifi开关变化广播
NETWORK_STATE_CHANGED_ACTION :wifi网络变化广播

SUPPLICANT_STATE_CHANGED_ACTION :wifi连接验证过程变化广播
SUPPLICANT_CONNECTION_CHANGE_ACTION :wifi开关变化广播

上面是wifi的还比较好区分的,
WIFI_STATE_CHANGED 这个是wifi开关,STATE_CHANGED 是wifi连接状态变化,多个wifi的就是开关的。

但是supplicant 这个确实不好记,和语义有点不符,
CONNECTION_CHANGE 的是开关变化,STATE_CHANGED是验证状态发生改变。
Connection就是连接的意思,但是CONNECTION_CHANGE居然是开关变化的广播;
不过这个 CONNECTION_CHANGE 尽量不要用了,没啥太大意义,wifi开关变化广播使用 WIFI_STATE_CHANGED_ACTION 就可以了。

2、wifi密码错误最正确的判断

	 case WifiManager.SUPPLICANT_STATE_CHANGED_ACTION: //wifi信息验证变化广播
			NetworkInfo.DetailedState detailedState = WifiInfo.getDetailedStateOf((SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE));
			LogUtil.inform("detailedState = " + detailedState);
			int error = intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, -1);
			LogUtil.inform("error = " + error);
			if (error == WifiManager.ERROR_AUTHENTICATING && detailedState == NetworkInfo.DetailedState.DISCONNECTED) { // 1 密码错误
				Toast.makeText(MainActivity.this, "wifi 密码错误!" ,Toast.LENGTH_LONG).show();
			}
		break;

网上很多文章只判断了error ==1 的情况,所以会多次弹框密码错误的情况。
所以网上的知识大多是仅供参考,还是要实际验证才可以。

3、如果查看wifi相关广播的Extra数据?

wifi广播携带了啥数据,这个怎么看?很多很多人都会有疑问?

这个其实不难,懂的都懂,学过一次后面就懂了,其实就是看api定义广播的地方,会写明该广播携带什么数据的。
这个不仅仅是针对wifi广播,其他任何广播其实都可以参考这样查看广播携带的数据。

比如wifi的某个广播:

WifiManager.java :

wifi连接变化广播 WifiManager.NETWORK_STATE_CHANGED_ACTION :

看源码的定义:

    /**
     * Broadcast intent action indicating that the state of Wi-Fi connectivity
     * has changed. An extra provides the new state
     * in the form of a {@link android.net.NetworkInfo} object.  No network-related
     * permissions are required to subscribe to this broadcast.
     *
     * <p class="note">This broadcast is not delivered to manifest receivers in
     * applications that target API version 26 or later.
     * @see #EXTRA_NETWORK_INFO // (1)Extra 数据,这里可能看不出啥类型的,继续找具体定义的地方就可以了
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";

	
	//(2)getParcelableExtra 返回的是NetworkInfo类型是数据, NetworkInfo 有啥数据可以自己看api或者打印出所有数据
    /**
     * The lookup key for a {@link android.net.NetworkInfo} object associated with the //返回类型
     * Wi-Fi network. Retrieve with
     * {@link android.content.Intent#getParcelableExtra(String)}. //获取额外数据的方法
     */
    public static final String EXTRA_NETWORK_INFO = "networkInfo";

这样就能看到广播返回的数据了吧,
主要思路:

1、查看广播携带的额外数据的字符串关键字
2、查看广播写得额外数据的类型
	case WifiManager.NETWORK_STATE_CHANGED_ACTION: //wifi连接变化广播,断开或者断开某个wifi
		NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
		LogUtil.inform("info = " + info);

再看一个其他类和其他类型的广播数据,ip变化广播:

ConnectivityManager.java

wifi连接变化广播 ConnectivityManager.CONNECTIVITY_ACTION :

	 // (1)Extra 数据,这里这里已经说明了是boolean类型,继续找具体定义的地方查看如何获取
     * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY
     * is set to {@code true} if there are no connected networks at all.
     *
     * @deprecated apps should use the more versatile {@link #requestNetwork},
     *             {@link #registerNetworkCallback} or {@link #registerDefaultNetworkCallback}
     *             functions instead for faster and more detailed updates about the network
     *             changes they care about.
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    @Deprecated
    public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";

	//(2)getBooleanExtra 返回的是 boolean 类型是数据,返回的是是否没有连接网络	
    /**
     * The lookup key for a boolean that indicates whether there is a
     * complete lack of connectivity, i.e., no network is available.
     * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
     */
    public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity";
	

上面的代码示例中,未添加这个数据打印,
这个数据也是今天看到的,代码中可以打印这个数据:

	case ConnectivityManager.CONNECTIVITY_ACTION: //网络变化广播,一般是ip地址变化
		boolean isNetNotConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
		//是否网络未连接
		LogUtil.inform("isNetNotConnectivity = " + isNetNotConnectivity); //如果有ip,返回就是false;也就是说断开wifi是返回 true,连接wifi是返回 false
		String wifiIp = FunctionUtil.getNetIpAddress("wlan0");
		LogUtil.inform("wifiIp = " + wifiIp);

学到了这个,其他任何广播都参考这样就可以找到广播携带的数据了。

是否可以在一个广播里面判断其他Extra 数据?

可能还有人会问,是否可以在广播中获取其他的 Extra 数据。

比如在 ConnectivityManager.CONNECTIVITY_ACTION 广播中是否可以获取wifi开关和wifi连接状态的 Extra 数据。

其实这个问题,学过基础知识的都知道,他没发过来的数据,你获取到的就是空的。所以没啥好疑问的。

	case ConnectivityManager.CONNECTIVITY_ACTION: //网络变化广播,一般是ip地址变化
		boolean isNetNotConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
		LogUtil.inform("isNetNotConnectivity = " + isNetNotConnectivity);
		
		NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); //这个数据就是会 null
		LogUtil.inform("info = " + info);

所以说广播里面携带了相关Extra的数据才能获取到,未携带的是获取不到的。

具体的过程,发送数据的具体信息,可以看源码里面发送广播的地方。

4、wifi其他相关广播

wifi相关广播,除了上面介绍的开关和连接相关的广播,
还有很多其他广播,直接在WifiManager.java里面搜索关键字“Broadcast intent action ”可以搜到里面所有的广播action。

其他广播:

    //wifi 验证信息变化
    /**
     * Broadcast intent action indicating that the credential of a Wi-Fi network
     * has been changed. One extra provides the ssid of the network. Another
     * extra provides the event type, whether the credential is saved or forgot.
     * @hide
     */
    @SystemApi
    public static final String WIFI_CREDENTIAL_CHANGED_ACTION = "android.net.wifi.WIFI_CREDENTIAL_CHANGED";

    //"Deauth Imminent" 是一种特定于 Wi-Fi 网络的管理帧,主要用于 Passpoint 认证过程
    /**
     * Broadcast intent action indicating that a Passpoint Deauth Imminent frame has been received.
     *
     * Included extras:
     * {@link #EXTRA_BSSID_LONG}
     * {@link #EXTRA_ESS}
     * {@link #EXTRA_DELAY}
     * {@link #EXTRA_URL}
     *
     * Receiver Required Permission: android.Manifest.permission.ACCESS_WIFI_STATE
     *
     * <p>Note: The broadcast is only delivered to registered receivers - no manifest registered
     * components will be launched.
     *
     * @hide
     */
    public static final String ACTION_PASSPOINT_DEAUTH_IMMINENT =
            "android.net.wifi.action.PASSPOINT_DEAUTH_IMMINENT";

    //热点开关变化
    @SystemApi
    public static final String WIFI_AP_STATE_CHANGED_ACTION =
        "android.net.wifi.WIFI_AP_STATE_CHANGED";

    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_CARRIER_PROVISIONING)
    public static final String ACTION_NETWORK_SETTINGS_RESET =
            "android.net.wifi.action.NETWORK_SETTINGS_RESET";

    //wifi信息重置?(恢复出厂设置那里,有个wif重置)
    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_CARRIER_PROVISIONING)
    public static final String ACTION_NETWORK_SETTINGS_RESET =
            "android.net.wifi.action.NETWORK_SETTINGS_RESET";

    //wifi信息修改
    @SystemApi
    public static final String CONFIGURED_NETWORKS_CHANGED_ACTION ="android.net.wifi.CONFIGURED_NETWORKS_CHANGE";

    //常用的wifi开关广播,其他常用广播就不再罗列了。
    /**
     * Broadcast intent action indicating that Wi-Fi has been enabled, disabled,
     * enabling, disabling, or unknown. One extra provides this state as an int.
     * Another extra provides the previous state, if available.  No network-related
     * permissions are required to subscribe to this broadcast.
     *
     * <p class="note">This broadcast is not delivered to manifest receivers in
     * applications that target API version 26 or later.
     *
     * @see #EXTRA_WIFI_STATE
     * @see #EXTRA_PREVIOUS_WIFI_STATE
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String WIFI_STATE_CHANGED_ACTION =
        "android.net.wifi.WIFI_STATE_CHANGED";

还有些广播,没使用过,并且看里面的注释也不清楚具体用途,就不一一罗列了。

可以看到很多不常用的广播都是需要系统权限才能监听到。

5、本文用到的获取ip代码

Android 获取ip地址多种方式介绍:
https://blog.csdn.net/wenzhi20102321/article/details/141673195

5、Android 蓝牙相关广播介绍

主要是开关,配对,取消配对,蓝牙名称修改等广播;
详细介绍:
https://blog.csdn.net/wenzhi20102321/article/details/134956116

标签:java,wifi,28,MainActivity,详解,onReceive,3984,Android
From: https://blog.csdn.net/wenzhi20102321/article/details/141678389

相关文章

  • Android 开发兼容性问题,TaskExecutionException等问题。
    1、问题描述:kapt'com.github.bumptech.glide:compiler:4.12.0'org.gradle.api.tasks.TaskExecutionException:Executionfailedfortask':app:kaptJlbDebugKotlin'.2、问题分析: 如果多人协作开发,从仓库clone\下载的项目代码,就说明其他开发人员使用这套代码是可以......
  • Android开发 - Serializable 接口对对象进行“打包”传递和接收后“解包”解析
    Serializable是什么Serializable是一种接口,用于将对象转换成字节流。通俗地说,Serializable是一种让对象能够“打包”和“解包”的方式,使得它们可以在存储和传输时保留其状态和数据Serializable的好处在程序中,我们经常需要在不同地方传递数据,比如在两个Activity之间传......
  • Android开发 - “序列化”与“反序列化”解析
    简介序列化和反序列化是计算机科学中两个非常常用的概念。简单来说,它们是将数据转换成不同形式的过程序列化(Serialization)序列化是将对象(比如一个Java对象或一个Python字典)转换成一种可以保存或传输的格式的过程。这种格式通常是字节流或字符串。通过序列化,你可以将一个......
  • OLED显示屏详解(IIC协议0.96寸 STM32)
     目录 一、介绍 二、模块原理1.原理图2.工作原理:SSD1306显存与命令三、程序设计main.c文件oled.h文件oled.c文件四、实验效果 五、资料获取项目分享一、介绍        OLED是有机发光二极管,又称为有机电激光显示(OrganicElectroluminescenceDisplay......
  • 数据结构-顺序表-详解
    数据结构-顺序表-详解1.是什么2.静态顺序表2.1实现2.2缺点3.动态顺序表3.1总览3.2动态顺序表的创建3.3初始化3.4销毁3.5打印3.6插入尾插头插3.7删除尾删头删1.是什么顺序表是一种基本的数据结构,它使用一组连续的内存空间来存储数据元素,这些元素在逻辑上也是连续......
  • Android App启动流程
    1.通过Launcher启动应用时,点击应用图标后,Launcher调用startActivity启动应用。 2.LauncherActivity最终调用Instrumentation的execStartActivity来启动应用。 3.Instrumentation调用ActivityManagerProxy(ActivityManagerService在应用进程的一个代理对象)......
  • flask limiter 详解
    在使用Flask-Limiter(或类似的限流库)时,你可以设置一个标志来表示当请求频率超过设定的限制后采取的行为。这通常用于实现特定的逻辑,如锁定用户、记录违规行为或发送警告。以下是一个基本示例,展示了如何在超过限制时设置标志:安装Flask-Limiter确保你已经安装了Flask-Limiter:......
  • C#学习笔记- 随机函数Random()的用法详解
    原文链接:https://www.jb51.net/article/90933.htmRandom.Next()返回非负随机数;Random.Next(Int)返回一个小于所指定最大值的非负随机数Random.Next(Int,Int)返回一个指定范围内的随机数,例如(-100,0)返回负数1、random(number)函数介绍random(number)返回一个0~number-1之间......
  • Android开发 - Parcel 类打包对象数据进行传递解析
    Parcel是什么Parcel是用于对象序列化和反序列化的一个类。通俗地说,它是一种轻量级的容器,常用于打包对象的数据(如基本类型和其他Parcelable对象),使它们能够在不同的组件(如Activity、Service等)之间传递Parcel的主要作用不同的组件(如Activity、Service)之间需要传递数据。......
  • Q: USB无线网卡搜不到路由器WiFi,但也能搜索到少部分信号。
    原因分析:一般在路由器的配置的无线信道是自动,路由器的2.4G频段有13个左右交叠的信道。由于USB无线网卡的设置信道区间可能不在无线信道范围内,导致无线网卡搜索不到对应wifi。解决问题:鼠标右键点击任务栏上的网络图标,点击“打开网络和Internet设置”,在弹出的设置窗口左边选择......