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

项目: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));
    }
}
项目:buildAPKsSamples    文件:WiFiDirectBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(WiFiServiceDiscoveryActivity.TAG, action);
    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
            Log.d(WiFiServiceDiscoveryActivity.TAG,
                    "Connected to p2p network. Requesting network details");
            manager.requestConnectionInfo(channel,
                    (ConnectionInfoListener) activity);
        } else {
            // It's a disconnect
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
            .equals(action)) {

        WifiP2pDevice device = (WifiP2pDevice) intent
                .getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        Log.d(WiFiServiceDiscoveryActivity.TAG, "Device status -" + device.status);

    }
}
项目:Audio-based-probing-of-the-environment    文件:WiFiBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {       
    String action = intent.getAction();
     if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
        Log.d(TAG, "inside WIFI_P2P_STATE_CHANGED_ACTION in onReceive()");
         int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
        } else {
        } 
     } 
     else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {
     }
     //If the connection is established/ disconnected with other peer
     else  if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
        Log.d(TAG, "inside WIFI_P2P_CONNECTION_CHANGED_ACTION");
         if (manager == null) {                return;            }
        NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
        Log.d(TAG,"getState():"+networkInfo.getState().toString()+",getTypeName(): "+networkInfo.getTypeName());
        if (networkInfo.isConnected()) {
            // if we are connected with the other device, request connection info
            Log.d(TAG, " requesting requestConnectionInfo()");
            if(this.service1!=null){
                manager.requestConnectionInfo(channel, (ConnectionInfoListener) service1);
            }
            //if(this.service2!=null){
            //  manager.requestConnectionInfo(channel, (ConnectionInfoListener) service2);
            //}
        } else {

        } 
     } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
        WifiP2pDevice device = (WifiP2pDevice) intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        Log.d(TAG, "Device status -" +getDeviceStatus(device.status));
    }
}
项目:android_opengles    文件:WiFiDirectBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(WiFiServiceDiscoveryActivity.TAG, action);
    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
            Log.d(WiFiServiceDiscoveryActivity.TAG,
                    "Connected to p2p network. Requesting network details");
            manager.requestConnectionInfo(channel,
                    (ConnectionInfoListener) activity);
        } else {
            // It's a disconnect
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
            .equals(action)) {

        WifiP2pDevice device = (WifiP2pDevice) intent
                .getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        Log.d(WiFiServiceDiscoveryActivity.TAG, "Device status -" + device.status);

    }
}
项目:WifiDirectDiscovery    文件:WiFiDirectBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(WiFiServiceDiscoveryActivity.TAG, action);
    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
            Log.d(WiFiServiceDiscoveryActivity.TAG,
                    "Connected to p2p network. Requesting network details");
            manager.requestConnectionInfo(channel,
                    (ConnectionInfoListener) activity);
        } else {
            // It's a disconnect
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
            .equals(action)) {

        WifiP2pDevice device = (WifiP2pDevice) intent
                .getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        Log.d(WiFiServiceDiscoveryActivity.TAG, "Device status -" + device.status);

    }
}
项目:dissertation-project    文件:WiFiDirectBroadcastReceiver.java   
@Override
public void onReceive(final Context context, final Intent intent) {
    final String action = intent.getAction();
    if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {

        if (mP2pManager == null) {
            return;
        }

        final 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
            mP2pManager.requestConnectionInfo(mChannel, (ConnectionInfoListener) mService);
        } else {
            // It's a disconnect
        }
    } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION
            .equals(action)) {

        final WifiP2pDevice device = (WifiP2pDevice) intent
                .getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
        Log.d(TAG, "Device status -" + device.status);

    }
}
项目: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);
        }
    }
项目:servicediscoverypg    文件:WifiDirectManager.java   
/**
 * Adds the Actions for the WifiP2pManager to IntentFilter and stores Manager and Channel
 * @param manager
 * @param channel
 * @param responseListener
 * @param connListener
 */
public WifiDirectManager(WifiP2pManager manager, Channel channel,
        final DnsSdResponseListener responseListener, ConnectionInfoListener connListener){

    intentFilter = new IntentFilter();

    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);

    this.manager = manager;
    this.channel = channel;

    this.connectionInfoListener = connListener;

    setupDnsSdResponseListeners(responseListener);
    setupDnsSdServiceRequest();
}