|
@@ -33,6 +33,8 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
|
|
|
|
|
|
private WifiP2pManager manager;
|
|
|
private WifiP2pManager.Channel channel;
|
|
|
+
|
|
|
+ private android.net.NetworkInfo.DetailedState networkState = null;
|
|
|
//private WifiP2pManager.PeerListListener peerListListener;
|
|
|
//private WifiP2pManager.ConnectionInfoListener connectionInfoListener;
|
|
|
|
|
@@ -89,8 +91,7 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- NetworkInfo networkInfo = (NetworkInfo) intent
|
|
|
- .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
|
|
|
+ NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
|
|
|
|
|
|
if (networkInfo.isConnected()) {
|
|
|
|
|
@@ -98,9 +99,13 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
|
|
|
// info to find group owner IP
|
|
|
manager.requestConnectionInfo(channel, this);
|
|
|
} else {
|
|
|
- // It's a disconnect
|
|
|
- this.eventListener.didDisconnect();
|
|
|
+ if (this.networkState != null && !this.networkState.equals(networkInfo.getDetailedState()) && networkInfo.getDetailedState() == android.net.NetworkInfo.DetailedState.DISCONNECTED){
|
|
|
+ // It's a disconnect
|
|
|
+ this.eventListener.didDisconnect();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ this.networkState = networkInfo.getDetailedState();
|
|
|
} else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
|
|
|
WifiP2pDevice device = intent.getParcelableExtra( WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
|
|
|
this.eventListener.deviceIsUpdated(device);
|
|
@@ -201,9 +206,11 @@ public class WiFiP2pBroadcastReceiver extends BroadcastReceiver implements WifiP
|
|
|
manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
|
|
|
@Override
|
|
|
public void onSuccess() {
|
|
|
+ Log.d("WiFiP2pBroadcastReceiver", " Discovering Peers initiated.");
|
|
|
}
|
|
|
@Override
|
|
|
public void onFailure(int reasonCode) {
|
|
|
+ Log.d("WiFiP2pBroadcastReceiver", " Discovering Peers failed. c="+reasonCode);
|
|
|
}
|
|
|
});
|
|
|
}
|