测试各个状态下的WIFI_STATE_CHANGED_ACTION广播

package com.JaradLee.mobilemanager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.util.Log;

public class ConnectionChangeReceiver extends BroadcastReceiver {

	public ConnectionChangeReceiver() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		 if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {//这个监听wifi的打开与关闭,与wifi的连接无关  
			 Log.v("my2", "收到WIFI_STATE_CHANGED_ACTION");   
			 int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, -1111);   
	         switch (wifiState) {   
	           case WifiManager.WIFI_STATE_DISABLED:  
	        	   Log.v("my2", "收到"+"WIFI_STATE_DISABLED");
	                break;   
	           case WifiManager.WIFI_STATE_DISABLING:   
	        	   Log.v("my2", "收到"+"WIFI_STATE_DISABLING");
	                break;
	           case WifiManager.WIFI_STATE_ENABLED:
	        	   Log.v("my2", "收到"+"WIFI_STATE_ENABLED");
	        	   break;
	           case WifiManager.WIFI_STATE_ENABLING:
	        	   Log.v("my2", "收到"+"WIFI_STATE_ENABLING");
	        	   break;
	           case WifiManager.WIFI_STATE_UNKNOWN:
	        	   Log.v("my2", "WIFI_STATE_UNKNOWN");
	                 
	          }   
	      }  

	}

	/**
	 * @param args
	 */

}

在无WIFI状态下打开WIFI 显示

02-21 15:05:03.160: V/my2(13502): 收到WIFI_STATE_CHANGED_ACTION

02-21 15:05:03.160: V/my2(13502): 收到WIFI_STATE_ENABLING

02-21 15:05:05.246: V/my2(13502): 收到WIFI_STATE_CHANGED_ACTION

02-21 15:05:05.246: V/my2(13502): 收到WIFI_STATE_ENABLED

在 WIFI状态下关闭WIFI 显示

02-21 15:12:18.168: V/my2(13502): 收到WIFI_STATE_CHANGED_ACTION

02-21 15:12:18.183: V/my2(13502): 收到WIFI_STATE_DISABLING

02-21 15:12:20.160: V/my2(13502): 收到WIFI_STATE_CHANGED_ACTION

02-21 15:12:20.160: V/my2(13502): 收到WIFI_STATE_DISABLED

 

PS:若开机时默认为打开WIFI状态会检测到WIFI_STATE_ENABLED,只会发送这一条广播

你可能感兴趣的:(安卓)