1.实用与平板和TV 的android设备
2.
IntentFilter wifiDeviceStateFilter = new IntentFilter(); //网络 wifiDeviceStateFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(wifiBroadcastReceiver,usbDeviceStateFilter);
3.
4.USBBroadcastReceiver usbBroadcastReceiver=new USBBroadcastReceiver();
class USBBroadcastReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { String action=intent.getAction(); if(ConnectivityManager.CONNECTIVITY_ACTION.equals(action)){ ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectivityManager.getActiveNetworkInfo(); if(info != null && info.isAvailable()) { String name = info.getTypeName(); LogUtil.i(TAG,"有网络 name="+name);
//有线是ETHERNET WIFI 就是WIFI if("ETHERNET".equals(name)) { EventBus.getDefault().post(new SettingBusEvent("LAN_CONNECTED")); } } else { EventBus.getDefault().post(new SettingBusEvent("LAN_DISCONNECTED")); LogUtil.i(TAG,"没有网络 name="+name); } } } };