public class netReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent wifi = new Intent();
if(isWifi(context)){
wifi = new Intent(context, MyService.class);
context.startService(intent);
}else{
wifi.setAction("net.s5c.Changelink.wifiOff");
sendBroadcast(wifi);
}
Toast.makeText(context, "监听到WIFI动作", Toast.LENGTH_LONG).show();
}
public static boolean isWifi(Context mContext) {
ConnectivityManager connectivityManager = (ConnectivityManager) mContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null
&& activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
return false;
}
}