来自文件:
https://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html#connect
我知道当BroadcastReceiver连接 成功 时会通知我们,如下所示:
...
} else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
if (mManager == null) {
return;
}
NetworkInfo networkInfo = (NetworkInfo) intent
.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
if (networkInfo.isConnected()) {
// We are connected with the other device, request connection
// info to find group owner IP
mManager.requestConnectionInfo(mChannel, connectionListener);
}
...
连接如何 失败 ,有谁知道怎么抓住它?
答案 0 :(得分:0)
我发现这种方式可以捕获连接尝试失败:
...
else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
Log.i(TAG, "networkInfo: " + networkInfo.toString());
...
}
...
logcat显示:
networkInfo:NetworkInfo:type:WIFI_P2P [],state:DISCONNECTED / FAILED ,原因:(未指定),extra:(none),漫游:false,failover:false, isAvailable:true,simId:0