Android Open Source - ExampleChopping Wifi Network Changed Receiver






From Project

Back to project page ExampleChopping.

License

The source code is released under:

Apache License

If you think the Android project ExampleChopping listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.chopping.example;
//from  w w  w .j  a  v a 2  s .  c  o m
import com.chopping.example.bus.WifiEvent;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import de.greenrobot.event.EventBus;

/**
 * Receiver to detect status of Wifi.
 */
public final class WifiNetworkChangedReceiver extends BroadcastReceiver{

  @Override
  public void onReceive(Context context, Intent intent) {
    NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    if(info!=null && TextUtils.equals(info.getTypeName(), "WIFI")) {
      EventBus.getDefault().post(new WifiEvent(info.isConnected()));
    }
  }
}




Java Source Code List

com.chopping.example.App.java
com.chopping.example.MainActivity.java
com.chopping.example.OtherActivity.java
com.chopping.example.Prefs.java
com.chopping.example.WifiNetworkChangedReceiver.java
com.chopping.example.bus.WifiEvent.java
com.chopping.example.data.DOUser.java
com.chopping.example.data.DOUsers.java