Java 类android.net.wifi.p2p.WifiP2pConfig 实例源码

项目:mDL-ILP    文件:WiFiDirectConnection.java   
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
            peerListener.connectionSuccess();
        }

        @Override
        public void onFailure(int reason) {
            peerListener.connectionFailure();
            Toast.makeText(activity, "Connect failed. Retry.", Toast.LENGTH_SHORT).show();
        }
    });
}
项目:mDL-ILP    文件:WiFiDirectConnection.java   
@Override
public void onPeersAvailable(WifiP2pDeviceList wifiP2pDeviceList) {

    if (!connectionAttemptInProgress.compareAndSet(false, true)) {
        return;
    }

    if (connected.get()) {
        return;
    }

    for (WifiP2pDevice device : wifiP2pDeviceList.getDeviceList()) {
        if (device.deviceAddress.equals(target)) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            config.groupOwnerIntent = 0; // I want the other device to be the group owner (or 'server')

            Log.d(TAG, "Trying to connect to "+device.deviceAddress+" "+device.deviceName+" Owner: "+device.isGroupOwner());

            connect(config);
            break;
        }
    }
}
项目:TK_1701    文件:WiFiDirect.java   
protected void connect(WifiP2pConfig config) {
    toast("みつけた!");
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
            Log.i(TAG,"p2p connect(try) success");
        }

        @Override
        public void onFailure(int reasonCode) {
            Log.i(TAG,"p2p connect(try) failure" + reasonCode);
        }
    });
}
项目:LittleBitLouder    文件:WifiP2pSender.java   
private void connectToPeer (WifiP2pDevice device)
{
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;

    mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {

        }
    });

}
项目:buildAPKsSamples    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:libcommon    文件:WiFiP2pHelper.java   
/**
 * 指定した機器へ接続を試みる
 * @param config
 * @throws IllegalStateException
 */
public void connect(@NonNull final WifiP2pConfig config) throws IllegalStateException {
    if (DEBUG) Log.v(TAG, "connect:config=" + config);
    if (mChannel != null) {
        mWifiP2pManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
            @Override
            public void onSuccess() {
                // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
            }
            @Override
            public void onFailure(int reason) {
                callOnError(new RuntimeException("failed to connect, reason=" + reason));
            }
        });
    } else {
        throw new IllegalStateException("not registered");
    }
}
项目:WiFi-Buddy    文件:WifiDirectHandler.java   
/**
 * Initiates a connection to a service
 * @param service The service to connect to
 */
public void initiateConnectToService(DnsSdService service) {
    // Device info of peer to connect to
    WifiP2pConfig wifiP2pConfig = new WifiP2pConfig();
    wifiP2pConfig.deviceAddress = service.getSrcDevice().deviceAddress;
    wifiP2pConfig.wps.setup = WpsInfo.PBC;

    // Starts a peer-to-peer connection with a device with the specified configuration
    wifiP2pManager.connect(channel, wifiP2pConfig, new WifiP2pManager.ActionListener() {
        // The ActionListener only notifies that initiation of connection has succeeded or failed

        @Override
        public void onSuccess() {
            Log.i(TAG, "Initiating connection to service");
        }

        @Override
        public void onFailure(int reason) {
            Log.e(TAG, "Failure initiating connection to service: " + FailureReason.fromInteger(reason).toString());
        }
    });
}
项目:Nucleus    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.

        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:Practice    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:Practice    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:Practice    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:Practice    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            Toast.makeText(WiFiDirectActivity.this, "连接成功,选择文件发送",
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:Practice    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:android-qr-data-transfer    文件:TransferActivity.java   
/**
 * Connect to the desired peer.
 *
 * @param deviceMacAddress the MAC address of the Server peer to connect with.
 */
private void connect(String deviceMacAddress) {
    // Create other device config
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = deviceMacAddress;
    config.wps.setup = WpsInfo.PBC;
    config.groupOwnerIntent = 0; // I want the other device to be the Group Owner !!

    // Perform connection
    manager.connect(channel, config, new ActionListener() {
        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(TransferActivity.this, R.string.aqrdt_error_connection_failed, Toast.LENGTH_SHORT).show();

            // Error during connection to the peer. Force the Activity to be finished.
            finishTransmissionWithError();
        }
    });
}
项目:Audio-based-probing-of-the-environment    文件:WifiClient.java   
public synchronized void connectP2p(WifiClientP2pService peer) {
    Log.d(TAG,"inside connectp2p ");
    /***auto device list***/
    /***auto device list***/
            Log.d(TAG,"device address: "+peer.getDevice().deviceAddress);
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = peer.getDevice().deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            //Toast.makeText(getApplicationContext(), "Trying to connect with "+config.deviceAddress, Toast.LENGTH_SHORT).show();
            if (serviceRequest != null)
                manager.removeServiceRequest(channel, serviceRequest,new ActionListener() {
                    public void onSuccess() {           }
                    public void onFailure(int arg0) {   }
                });
                manager.connect(channel, config, new ActionListener() {
                    public void onSuccess() {           Log.d(TAG,"Connecting to device");            }
                    public void onFailure(int errorCode) {      Log.d(TAG,"failed Connecting to device");         }
            });
    /***auto device list***/        
    /***auto device list***/
}
项目:RevolutionStarbucks    文件:MainActivity.java   
private void SendImage(WifiP2pDevice device)
{
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;

    mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            throw new RuntimeException("Oh god damn");
        }
    });
}
项目:susurrus-android-app    文件:WifiDirectService.java   
/**
 * Establishes a connection to a local "susurrus"-service.
 * @param roomModel
 * @param feedbackActivity
 */
public void connectToLocalService(final RoomModel roomModel, final MainActivity feedbackActivity) {
    WifiP2pConfig connectionConfig = new WifiP2pConfig();
    connectionConfig.deviceAddress = roomModel.getOwnerAddr();
    // user connects, don't make him the owner
    connectionConfig.groupOwnerIntent = 0;
    // connectionConfig.wps.setup = WpsInfo.INVALID;
    connectionConfig.wps.setup = WpsInfo.PBC;

    wifiDirectManager.connect(wifiDirectChannel, connectionConfig, new WifiP2pManager.
            ActionListener() {

        @Override
        public void onSuccess() {
            //feedbackActivity.showRoomJoinFeedbackUpdate(GROUP_CONNECTED);
        }

        @Override
        public void onFailure(int reason) {
            Log.d(LOG_TAG, "Connection to room failed: " + reason);

            feedbackActivity.showRoomJoinFeedbackUpdate(GROUP_NOT_CONNECTED);
        }
    });
}
项目:NFD-android    文件:NDNController.java   
public void connect(WifiP2pDevice peerDevice) {
  WifiP2pConfig config = new WifiP2pConfig();
  config.deviceAddress = peerDevice.deviceAddress;
  config.wps.setup = WpsInfo.PBC;
  wifiP2pManager.connect(channel, config, new WifiP2pManager.ActionListener() {
    @Override
    public void onSuccess() {
      // onReceive() in WDBroadcastReceiver will receive an intent
    }

    @Override
    public void onFailure(int reason) {

      String reasonString = WDBroadcastReceiver
        .getWifiP2pManagerMessageFromReasonCode(reason);

      Log.e(TAG, "There was an issue with initiating connection reason: " + reasonString);
    }
  });
}
项目:WifiPairing    文件:WifiConnection.java   
public void Connect(String address) {

        WifiP2pConfig config = new WifiP2pConfig();
        config.deviceAddress = address;
        config.wps.setup = WpsInfo.PBC;

        p2p.connect(channel, config, new WifiP2pManager.ActionListener() {
            @Override
            public void onSuccess() {
                debug_print("Connecting to service" );
            }

            @Override
            public void onFailure(int errorCode) {
                debug_print("Failed connecting to service : " + errorCode);
            }
        });
    }
项目:GoBang    文件:Salut.java   
private void connectToDevice(final SalutDevice device, final SalutCallback onFailure)
{

    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.macAddress;
    manager.connect(channel, config, new WifiP2pManager.ActionListener() {

        @Override
        public void onSuccess() {
            Log.d(TAG, "Attempting to connect to another device.");
            lastConnectedDevice = device;
        }

        @Override
        public void onFailure(int reason) {
            onFailure.call();
            Log.e(TAG, "Failed to connect to device. ");
        }
    });
}
项目:Salut    文件:Salut.java   
private void connectToDevice(final SalutDevice device, final SalutCallback onFailure) {

        WifiP2pConfig config = new WifiP2pConfig();
        config.deviceAddress = device.macAddress;
        manager.connect(channel, config, new WifiP2pManager.ActionListener() {

            @Override
            public void onSuccess() {
                Log.d(TAG, "Attempting to connect to another device.");
                lastConnectedDevice = device;
            }

            @Override
            public void onFailure(int reason) {
                onFailure.call();
                Log.e(TAG, "Failed to connect to device. ");
            }
        });
    }
项目:swan-sense-studio    文件:WifiDirectAutoAccept.java   
/**
 * Callback that reports connection attempts.
 * <p/>
 * The device parameter provides information about the remote
 * device that is trying to form a P2P group.  The config
 * parameter describes the type of connection being made.
 * <p/>
 * To accept a connection request, call manager.connect.
 * config.wps.pin should be assigned within this method for
 * PIN-based group formation before passing the config to
 * manager.connect.
 */
@SuppressWarnings("unused")
public void onConnectionRequested(WifiP2pDevice device, WifiP2pConfig config) {
    Log.d(TAG, "onConnectionRequested");
    Log.d(TAG, "    device: " + device.deviceAddress + " " + device.deviceName);
    Log.d(TAG, "    config: " + config.wps.setup + " " + config.wps.pin);
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Log.d(TAG, "Connect failed");
        }
    });
}
项目:Scatterbrain    文件:WifiManager.java   
public void connectToPeer(final WifiP2pManager.Channel c,final  WifiP2pDevice target) {
    Log.i(TAG, "Manually connecting to peer " + target.deviceName + " with  address " +
    target.deviceAddress);

    final WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = target.deviceAddress;
    manager.connect(c, config, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {
            connectedList.put(target, config);
            Log.v(TAG, "Connection succeeded for " + target.deviceName);
        }

        @Override
        public void onFailure(int reason) {
            Log.e(TAG, "Failed to connect to device " + target.deviceName + "with address " +
            target.deviceAddress);
        }
    });
}
项目:Scatterbrain    文件:WifiManager.java   
private void cleanupConnections() {
    Log.v(TAG, "Running connection list garbage collector");
    final Thread connectionGC = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized (connectedList) {
                for (Map.Entry<WifiP2pDevice, WifiP2pConfig> s : connectedList.entrySet()) {
                    if (s.getKey().status != WifiP2pDevice.CONNECTED) {
                        connectedList.remove(s.getKey());
                    }
                }
            }
        }
    });

    connectionGC.start();

}
项目:Scatterbrain    文件:WifiManager.java   
private void connectToDevice(WifiP2pDevice dev) {
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = dev.deviceAddress;
    config.wps.setup = WpsInfo.PBC;

    manager.connect(channel, config, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {
            //this gets broadcast to WifiDirectBroadcastReceiver
            //here
        }

        @Override
        public void onFailure(int reason) {
            Log.e(TAG, "Failed to connect to wifidirect device");
        }
    });
}
项目:AndroidSideLoading    文件:DeviceDetailFragment.java   
private void connect(){

        WifiP2pConfig config = new WifiP2pConfig();
        config.deviceAddress = device.deviceAddress;
        config.wps.setup = WpsInfo.PBC;
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
        progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                "Connecting to :" + device.deviceAddress, true, true
//                        new DialogInterface.OnCancelListener() {
//
//                            @Override
//                            public void onCancel(DialogInterface dialog) {
//                                ((DeviceActionListener) getActivity()).cancelDisconnect();
//                            }
//                        }
        );
        ((DevicesListFragment.DeviceActionListener) getActivity()).connect(config);
    }
项目:android_opengles    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:commcare-android    文件:DeviceListFragment.java   
/**
 * Initiate a connection with the peer.
 */
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Log.d(TAG, "onListItemClick");
    WifiP2pDevice device = (WifiP2pDevice)getListAdapter().getItem(position);
    Log.d(TAG, "device is: " + device.deviceAddress);
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();
    }
    progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
            "Connecting to :" + device.deviceAddress, true, true);

    ((DeviceActionListener)getActivity()).connect(config);

}
项目:commcare-android    文件:CommCareWiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    Logger.log(TAG, "connecting to wi-fi peer");

    mManager.connect(mChannel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            myStatusText.setText(localize("wifi.direct.connect.success"));
        }

        @Override
        public void onFailure(int reason) {
            Logger.log(TAG, "Connection to peer failed");
            Toast.makeText(CommCareWiFiDirectActivity.this,
                    localize("wifi.direct.connect.failed"),
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:syncarnet    文件:PeerSelection.java   
@Override
public void onPeerSelected(WifiP2pDevice device) {
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    synCarnet.syncService.setConnecting(true);
    progressDialog = ProgressDialog.show(synCarnet, synCarnet.getString(R.string.backCancel),
    synCarnet.getString(R.string.connectingTo) + device.deviceAddress, true, true);
    ServiceStatic.setDevice(device.deviceName, device.deviceAddress);
    manager.connect(channel, config, new ActionListener() {
        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(synCarnet, synCarnet.getString(R.string.connectFailed),
            Toast.LENGTH_SHORT).show();
            Log.d(TAG, "Connect failed : "+reason);

        }
    });
}
项目:collision-avoidance-warning    文件:WifiBroadcastReceiver.java   
/**
 * Acquire new peers list and connect
 *
 * @param WifiP2pDeviceList peerList of devices!
 */
@Override
public void onPeersAvailable(WifiP2pDeviceList peerList)
{
    // Wipe old list
    // @todo filter connected peers (by address) out of new list
    this.peers.clear();

    // Add new list
    this.peers.addAll(peerList.getDeviceList());

    // Iterate to connect
    for (WifiP2pDevice device : this.peers) {

        // Prepare Config /w Device Address
        WifiP2pConfig wifiP2pConfig = new WifiP2pConfig();
        wifiP2pConfig.deviceAddress = device.deviceAddress;

        // Connect
        // @todo add success/failure handling
        this.wifiP2pManager.connect(this.wifiP2pChannel, wifiP2pConfig, null);
    }
}
项目:wifi_p2p    文件:MainActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    // TODO Auto-generated method stub
    mManager.connect(mChannel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WifiDirectBroadcastReceiver will notify us

        }

        @Override
        public void onFailure(int reason) {
            showMessage ("Connect failed: "+reason);

        }
    });
    return;

}
项目:aperi    文件:AperiMainActivity.java   
@Override
public void connect(WifiP2pConfig config)
{
    mManager.connect(mChannel, config, new ActionListener() {

        @Override
        public void onSuccess()
        {
            // AperiBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason)
        {
            Toast.makeText(AperiMainActivity.this,
                    "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:higgs-bot    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:higgs-bot    文件:WiFiDirectActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WiFiDirectBroadcastReceiver will notify us. Ignore for now.
        }

        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",
                    Toast.LENGTH_SHORT).show();
        }
    });
}
项目:wifi_p2p    文件:MainActivity.java   
@Override
public void connect(WifiP2pConfig config) {
    // TODO Auto-generated method stub
    mManager.connect(mChannel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            // WifiDirectBroadcastReceiver will notify us

        }

        @Override
        public void onFailure(int reason) {
            showMessage ("Connect failed: "+reason);

        }
    });
    return;

}
项目:dissertation-project    文件:WifiDirectSdHelper.java   
private void initialiseDnsTxtRecordListener() {
    mDnsTxtRecordListener = new DnsSdTxtRecordListener() {

        @Override
        public void onDnsSdTxtRecordAvailable(String fullDomainName,
                Map<String, String> txtRecordMap, WifiP2pDevice srcDevice) {

            if (fullDomainName.contains(SERVICE_INSTANCE)) {

                WifiP2pConfig config = new WifiP2pConfig();
                config.deviceAddress = srcDevice.deviceAddress;
                config.groupOwnerIntent = 0;
                config.wps.setup = WpsInfo.PBC;

                mP2PManager.connect(mChannel, config, null);
            }

        }
    };
}
项目:TK_1701    文件:WiFiDirectConnector.java   
@Override
public void onPeersAvailable(WifiP2pDeviceList peerList) {
    peers.clear();
    peers.addAll(peerList.getDeviceList());
    //Log.d(TAG,peers.toString());

    // if Device on Inviting or Connected, terminate.
    if (onConnecting || wfd.status.p2p_status.equals("Connected") || wfd.status.p2p_status.equals("Invited")){
        return;
    }

    // Search Opponent Device in Peer List
    for(int i=0; i<peers.size(); ++i){
        if (peers.get(i).deviceName.equals(wfd.getOpponentID())){
            onConnecting = true;

            WifiP2pDevice device = peers.get(i);
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;

            Log.d(TAG,"connect challenge");
            wfd.connect(config);
            return;
        }
    }

    // Can't Found Opponent Device
    Log.d(TAG,"can't found device");
}
项目:aos-FileCoreLibrary    文件:FileTransferService.java   
private void connect(String deviceAddress){
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    config.groupOwnerIntent = 0; //Client mustn't be group owner
    mManager.connect(mChannel, config, null);
}
项目:buildAPKsSamples    文件:WiFiServiceDiscoveryActivity.java   
@Override
public void connectP2p(WiFiP2pService service) {
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = service.device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    if (serviceRequest != null)
        manager.removeServiceRequest(channel, serviceRequest,
                new ActionListener() {

                    @Override
                    public void onSuccess() {
                    }

                    @Override
                    public void onFailure(int arg0) {
                    }
                });

    manager.connect(channel, config, new ActionListener() {

        @Override
        public void onSuccess() {
            appendStatus("Connecting to service");
        }

        @Override
        public void onFailure(int errorCode) {
            appendStatus("Failed connecting to service");
        }
    });
}