我已按照以下链接连接到本地 wifi。它工作完美。我能够连接到我的本地wifi。
但是,我真的想要wifi的当前状态,我正在使用以下代码来获取wifi的状态。但不幸的是,我只能获得“禁用”、“启用”和“扫描”状态,我真的很想接收其他中间状态。
你能告诉我我做错了什么吗?
public class ConnectionChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
Message msg = new Message();
msg.what = 5;
Bundle b = new Bundle();
String sStatus = "UnKnown";
switch(info.getDetailedState()){
case AUTHENTICATING:
sStatus = "Authenticating...";
break;
case CONNECTED:
sStatus = "Connected";
break;
case CONNECTING:
sStatus = "Connecting...";
break;
case DISCONNECTED:
sStatus = "Disconnected";
break;
case DISCONNECTING:
sStatus = "Disconnecting...";
break;
case FAILED:
sStatus = "Failed";
break;
case IDLE:
sStatus = "Idle";
break;
case OBTAINING_IPADDR :
sStatus = "Obtaining IP Address...";
break;
case SCANNING:
sStatus = "Scanning...";
break;
case SUSPENDED:
sStatus = "Suspended";
break;
}
b.putString("status", sStatus);
msg.setData(b);
mHandler.sendMessage(msg);
}
}
我通过以下方式注册广播接收器
IntentFilter filter = new IntentFilter(
ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkStateReceiver, filter);