Wifi广播状态

intent-filters填写

- android.net.wifi.WIFI_STATE_CHANGED
- action android:name="android.net.wifi.STATE_CHANGE
- android.net.wifi.supplicant.CONNECTION_CHANGE

 

权限

uses-permission android:name="android.permission.ACCESS_WIFI_STATE"

 

final String action = intent.getAction(); 
 
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) 
{ 
  NetworkInfo info = (NetworkInfo)intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); 
  if (info.getState().equals(NetworkInfo.State.CONNECTED)) 
  { 
    //do whatever you want when wifi is active and connected to a hotspot 
  } 
} 

 

还有这句如果需要

if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION))

你可能感兴趣的:(.net,android,Access)