the key is:
mWifiMgr.disconnect();
mWifiMgr.enableNetwork(wifiConfig.networkId, true);
mWifiMgr.reconnect();
and determining if the connection to the AP is established:
ConnectivityManager connectivityManager = (ConnectivityManager)
MyController.mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null){
networkInfo = connectivityManager.getActiveNetworkInfo();
}
if (networkInfo != null && networkInfo.isConnected()){
Log.v(TAG, "CONNECTED!! detailed state = " + networkInfo.getDetailedState());
break;
}
Log.v(TAG, "not connected!! reason = " + networkInfo.getReason());
沒有留言:
張貼留言