赞
踩
- IntentFilter mFilter = new IntentFilter();
- mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
- registerReceiver(mReceiver, mFilter);
- private BroadcastReceiver mReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo info = connectivityManager.getActiveNetworkInfo();
- if (info != null && info.isAvailable()) {
- String name = info.getTypeName();
- AppLog.Log("当前网络名称:" + name);
- } else {
- AppLog.Log("没有可用网络");
- }
- }
- };
unregisterReceiver(mReceiver);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。