public class AndroidWifiStateChangedDetect extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.registerReceiver(this.WifiStateChangedReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
}
private BroadcastReceiver WifiStateChangedReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE , WifiManager.WIFI_STATE_UNKNOWN);
switch(extraWifiState){
case WifiManager.WIFI_STATE_DISABLED:
Toast.makeText(AndroidWifiStateChangedDetect.this, "WIFI DISABLED", Toast.LENGTH_SHORT).show();
break;
case WifiManager.WIFI_STATE_DISABLING:
Toast.makeText(AndroidWifiStateChangedDetect.this, "WIFI DISABLING ", Toast.LENGTH_SHORT).show();
break;
case WifiManager.WIFI_STATE_ENABLED:
Toast.makeText(AndroidWifiStateChangedDetect.this, "WIFI ENABLED ", Toast.LENGTH_SHORT).show();
break;
case WifiManager.WIFI_STATE_ENABLING:
Toast.makeText(AndroidWifiStateChangedDetect.this, "WIFI ENABLING ", Toast.LENGTH_SHORT).show();
break;
case WifiManager.WIFI_STATE_UNKNOWN:
Toast.makeText(AndroidWifiStateChangedDetect.this, "WIFI UNKNOWN ", Toast.LENGTH_SHORT).show();
break;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);