赞
踩
- public class NetReceiver extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
- boolean isConnected = NetUtils.isNetworkConnected(context);
- System.out.println("网络状态:" + isConnected);
- System.out.println("wifi状态:" + NetUtils.isWifiConnected(context));
- System.out.println("移动网络状态:" + NetUtils.isMobileConnected(context));
- System.out.println("网络连接类型:" + NetUtils.getConnectedType(context));
- if (isConnected) {
- EventBus.getDefault().postSticky(new NetEvent(true));
- if (onNetConnect != null) {
- onNetConnect.onNetConnect();
- }
- } else {
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。