package com.example.possdkforandroid;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

public class WifiBroad extends BroadcastReceiver{
	public static boolean Wifistatus = true;
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		//intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)||
		if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
			System.out.println("网络状态改变");
			NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
			if(info.getState().equals(NetworkInfo.State.DISCONNECTED)){
				//断开
				Wifistatus = false;
				System.out.println("wifi断开");
				
			}
			if(info.getState().equals(NetworkInfo.State.CONNECTING)){
				Wifistatus = true;
				System.out.println("WiFi连接");
					
			}
		}else if(intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)){
			int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,WifiManager.WIFI_STATE_DISABLED);
			if(wifistate == WifiManager.WIFI_STATE_DISABLED){
				Wifistatus = false;
				System.out.println("系统关闭wifi");
			}
			
			if(wifistate == WifiManager.WIFI_STATE_ENABLED){
				Wifistatus = true;
				System.out.println("系统开启wifi");
			}
		}
	}

}
