Java 类android.net.wifi.p2p.WifiP2pManager.PeerListListener 实例源码

项目:klammer    文件:Peers.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Logg.d(TAG, "received action " + action);
    // request list of peers
    wifi.getManager().requestPeers(
            wifi.getChannel(), new PeerListListener() {
        @Override
        public void onPeersAvailable(WifiP2pDeviceList peers) {
            // retreive list of devices
            devices.clear();
            for (WifiP2pDevice device : peers.getDeviceList()) {
                devices.add(device);
            }
            onChange();

            // if number of peers drops to zero
            if (devices.size() == 0) {
                // check again
                discover();
            }
        }
    });
}
项目:aos-FileCoreLibrary    文件:WiFiDirectBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {

        // UI update to indicate wifi p2p status.
        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            // Wifi Direct mode is enabled
            listener.setIsWifiP2pEnabled(true);
        } else {
            listener.setIsWifiP2pEnabled(false);

        }
    } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
        // request available peers from the wifi p2p manager. This is an
        // asynchronous call and the calling activity is notified with a
        // callback on PeerListListener.onPeersAvailable()
        if (manager != null)
            manager.requestPeers(channel, (PeerListListener) listener);
    } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        if (manager == 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
            manager.requestConnectionInfo(channel, (ConnectionInfoListener) listener);
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        listener.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
                WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));
    }
}
项目:SPF    文件:WifiDirectMiddleware.java   
public void onPeerListChanged() {
    mManager.requestPeers(mChannel, new PeerListListener() {

        @Override
        public void onPeersAvailable(WifiP2pDeviceList peers) {
            Collection<WifiP2pDevice> peersCollection = peers.getDeviceList();
            updatePeerList(peersCollection);
        }
    });
}
项目:commcare-android    文件:CommCareWiFiDirectActivity.java   
@Override
public void updatePeers() {
    Logger.log(TAG, "Wi-Fi direct peers updating");
    mManager.requestPeers(mChannel, (PeerListListener)this.getSupportFragmentManager()
            .findFragmentById(R.id.frag_list));

}
项目:letv    文件:LeBoxNetworkManager.java   
public void requestP2pPeers(PeerListListener peerListListener) {
    LeBoxWifiDirectModel.getInstance().requestPeers(peerListListener);
}
项目:swan-sense-studio    文件:WDBroadcastReceiver.java   
@Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            log("wifi direct changed state", false);
            // Determine if Wifi P2P mode is enabled or not, alert the Activity.
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);

            if (state != WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                log("p2p not enabled", true);
            }
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
//          log("peer list changed", false);

            if (p2pManager != null) {
                p2pManager.requestPeers(p2pChannel, new PeerListListener() {
                    @Override
                    public void onPeersAvailable(WifiP2pDeviceList peers) {
//                      log("peer list changed", false);
                    }
                });
            }
        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
            // Respond to new connection or disconnections
            log("connection changed", false);

            if (p2pManager == null) {
                return;
            }

            NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);

            if (networkInfo.isConnected()) {
                log("connected", false);

                // We are connected with the other device, request connection info to find group owner IP
                p2pManager.requestConnectionInfo(p2pChannel, new ConnectionInfoListener() {
                    @Override
                    public void onConnectionInfoAvailable(WifiP2pInfo info) {
                        InetAddress groupOwnerAddress = info.groupOwnerAddress;

                        if (info.groupFormed && info.isGroupOwner) {
                            wdManager.connected(groupOwnerAddress.getHostAddress(), true);
                            log("[connected] group owner with ip = " + groupOwnerAddress.getHostAddress() + " (me)", true);
                        } else if (info.groupFormed) {
                            wdManager.connected(groupOwnerAddress.getHostAddress(), false);
                            log("[connected] group owner ip = " + groupOwnerAddress.getHostAddress(), true);
                        }

                        wdManager.setConnected(true);
                    }
                });
            } else {
                // this is called also when the other peer refuses connection
                wdManager.setConnected(false);
                log("disconnected", true);
            }
        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
            // This is called when the connectivity is lost
            // TODO unregister here any registered expressions with the remote
            wdManager.setConnected(false);
            wdManager.resetPeers();
            log("connectivity lost", true);
        }
    }
项目:ShareVideo    文件:WiFiDirectBroadcastReceiver.java   
@Override
       public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
            // Determine if Wifi P2P mode is enabled or not, alert
            // the Activity.

            Log.d(TAG, "WIFI_P2P_STATE_CHANGED_ACTION");
            int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
            if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
                fetcher.setIsWifiP2pEnabled(true);
            } else {
                fetcher.setIsWifiP2pEnabled(false);
            }
        } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {

            // The peer list has changed!  We should probably do something about
            // that.

            // request available peers from the wifi p2p manager. This is an
            // asynchronous call and the calling activity is notified with a
            // callback on PeerListListener.onPeersAvailable()
            if (manager != null) {
                manager.requestPeers(channel, (PeerListListener)fetcher);
            }
            Log.d(TAG, "WIFI_P2P_PEERS_CHANGED_ACTION");



        } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

            // Connection state changed!  We should probably do something about
            // that.
            Log.d(TAG, "WIFI_P2P_CONNECTION_CHANGED_ACTION");
            if (manager == 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

                manager.requestConnectionInfo(channel, fetcher);
            }

        } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
//            DeviceListFragment fragment = (DeviceListFragment) activity.getFragmentManager()
//                    .findFragmentById(R.id.frag_list);
//            fragment.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
//                    WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));

        } 
    }