@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; } } }
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) { } }); }
/** * 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()); } }); }
/** * 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(); } }); }
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***/ }
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"); } }); }
/** * 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); } }); }
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); } }); }
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); } }); }
@Override protected void onStart() { /* * increment timeout bar per second. */ mTimer = new Timer(false); mTimer.schedule(new TimerTask() { @Override public void run() { mHandler.post(new Runnable() { @Override public void run() { mTimeoutBar.incrementProgressBy(1); } }); } }, 1000, 1000); mContext.registerReceiver(mReceiver, mFilter); WpsInfo wpsConfig = new WpsInfo(); wpsConfig.setup = mWpsSetup; mWifiManager.startWps(wpsConfig, mWpsListener); }
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"); } }); }
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); }
/** * 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); }
@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); } }); }
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); } } }; }
@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"); }
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); }
@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"); } }); }
private void connect(WifiP2pDevice device) { duration = System.currentTimeMillis() - startTime; Log.d(TAG, "connect WifiP2pDevice: starting connection (duration: "+duration+" ms)"); WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = device.deviceAddress; config.wps.setup = WpsInfo.PBC; manager.connect(channel, config, new LogActionListener("WiFiClient.connect")); }
/** * 指定したMACアドレスの機器へ接続を試みる * @param remoteMacAddress */ public void connect(@NonNull final String remoteMacAddress) { if (DEBUG) Log.v(TAG, "connect:remoteMacAddress=" + remoteMacAddress); final WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = remoteMacAddress; config.wps.setup = WpsInfo.PBC; connect(config); }
/** * 指定した機器へ接続を試みる * @param device */ public void connect(@NonNull final WifiP2pDevice device) { if (DEBUG) Log.v(TAG, "connect:device=" + device); final WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = device.deviceAddress; config.wps.setup = WpsInfo.PBC; connect(config); }
public void connectDevice(WifiP2pDevice device, ActionListener listener) { Log.d(TAG, "WifiP2pHelper-->connectDevice()"); WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = device.deviceAddress; config.wps.setup = WpsInfo.PBC; manager.connect(channel, config, listener); }
public void connect(WifiP2pDevice device) { // Picking the first device found on the network. WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = device.deviceAddress; config.wps.setup = WpsInfo.PBC; mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.e("connect","onSuccess"); } @Override public void onFailure(int reason) { switch (reason){ case WifiP2pManager.ERROR: Log.e("connect","ERROR"); break; case WifiP2pManager.P2P_UNSUPPORTED: Log.e("connect","P2P_UNSUPPORTED"); break; case WifiP2pManager.BUSY: Log.e("connect","BUSY"); break; case WifiP2pManager.NO_SERVICE_REQUESTS: Log.e("connect","NO_SERVICE_REQUESTS"); break; } } }); }
@Override public void onPeersAvailable(WifiP2pDeviceList peerList) { boolean flag = false; WifiP2pConfig config = new WifiP2pConfig(); for (WifiP2pDevice peer : peerList.getDeviceList()) { if (peer.deviceAddress.equals(client.getGroupOwnerMacAddress())) { config.deviceAddress = peer.deviceAddress; flag = true; break; } } if (!flag) { client.getOutcomeBroadcastSender().serviceStoppedShowDialogFinishActivity("Keine Lobby gefunden."); client.stopSelf(); return; } config.wps.setup = WpsInfo.PBC; client.getmManager().connect(client.getmChannel(), config, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { // WiFiDirectBroadcastReceiver will notify us. Ignore for now. } @Override public void onFailure(int reason) { Log.v("ClientPeerListListener", "Connect failed. Retry."); } }); }
@Override public void connect(String address) { if (isConnected()) return; // Right after a redirect, this does not work. For some reason the WifiP2pConfig is regarded // as invalid by the Android framework. This can be solved by calling discoverPeers() to // refresh the peers list, but that brings other problems. I don't really know how to fix this... final WifiP2pConfig config = new WifiP2pConfig(); config.groupOwnerIntent = -1; config.wps.setup = WpsInfo.PBC; config.deviceAddress = address; // The result will be the WIFI_P2P_CONNECTION_CHANGED_ACTION broadcast event // for which we have to be registered. mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.d(TAG, "Wifi P2P Connection established."); } @Override public void onFailure(int i) { Log.d(TAG, "Failed to establish Wifi P2P Connection"); } }); }
public void connect(String deviceAddress, boolean beGO) { WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = deviceAddress; if (beGO) { config.groupOwnerIntent = 15; } config.wps.setup = WpsInfo.PBC; mWifiP2pManager.connect(mChannel, config, new NFGameActionListener("connect")); }
private void createGroup() { WfdLog.d(TAG, "createGroup()"); if (isGroupCreated||!connected) { WfdLog.d(TAG, "group already created or middleware not started"); return; } WfdLog.d(TAG, "attempt to create group"); WifiP2pConfig config = new WifiP2pConfig(); String deviceAddress = selectDeviceAddess(); if (deviceAddress == null) { WfdLog.d(TAG, "no device address eligible for connection"); return; } WfdLog.d(TAG, "connect target device found, device address: " + deviceAddress); config.deviceAddress = deviceAddress; config.wps.setup = WpsInfo.PBC; isGroupCreated = true; mManager.connect(mChannel, config, new ActionListener() { @Override public void onSuccess() { WfdLog.d(TAG, "connect() succeded"); } @Override public void onFailure(int reason) { isGroupCreated = false; WfdLog.d(TAG, "connect() failed"); } }); }
public void connectToP2pDevice(final WifiP2pDevice p2pDevice) { mPauseDiscovery = true; mWifiP2pManager.stopPeerDiscovery(mChannel, new DebugListener("stopPeerDiscovery() due to connection")); mConnectedConfig.deviceAddress = p2pDevice.deviceAddress; mConnectedConfig.wps.setup = WpsInfo.PBC; final String device = String.format("%s (%s)", p2pDevice.deviceAddress, p2pDevice.deviceName); mWifiP2pManager.connect(mChannel, mConnectedConfig, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.w(LOG_TAG, "Successfully connected to " + device); onConnected(p2pDevice); } @Override public void onFailure(final int reason) { if (reason == WifiP2pManager.P2P_UNSUPPORTED) { mWifiP2pUiListener.onP2PNotSupported(); } else if (reason == WifiP2pManager.BUSY) { Log.d(LOG_TAG, "Failed to connect to "+device+ ", device busy"); } else { Log.d(LOG_TAG, "Failed to connect to "+device + ", reason:" + reason); retryConnection(p2pDevice); } } }); }
@Override public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg) { // TODO Auto-generated method stub Log.v(TAG, pos + " " + arg); WifiP2pDevice device = peers.get(pos); final WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = device.deviceAddress; config.wps.setup = WpsInfo.PBC; Log.i(TAG, "try to connect to " + device.toString()); progressDialog = ProgressDialog.show(getActivity(), "Connecting Other Peers", "Please wait for connecting completed."); alertdialog = new AlertDialog.Builder(getActivity()) .setTitle("Discover Results") .setMessage("Peer: " + device.deviceName) .setPositiveButton("Connect", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub connect(config); } }).setNegativeButton("Cancel", null).show(); }
/** * returns true if the sending thread from Pusher has to wait for getting the IP of user */ public boolean connect(WDSwanDevice user, Thread thread) { if (user.getDevice() == null) { return false; } if (user.getIp() != null) { return false; } WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = user.getDevice().deviceAddress; config.wps.setup = WpsInfo.PBC; waitingThread = thread; waitingUser = user; Log.d(TAG, "connecting to peer"); p2pManager.connect(p2pChannel, config, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.d(TAG, "connection succesful"); } @Override public void onFailure(int reason) { Log.d(TAG, "Connect failed. Retry."); switch (reason) { case WifiP2pManager.P2P_UNSUPPORTED: Log.e(TAG, "p2p unsupported"); break; case WifiP2pManager.ERROR: Log.e(TAG, "internal error"); break; case WifiP2pManager.BUSY: Log.e(TAG, "busy"); break; default: break; } } }); return true; }
@Override public void onPeersAvailable(WifiP2pDeviceList peerList) { Log.d("peerListListener", "onPeersAvailable"); //Clear the original list and add to the new list peers.clear(); peers.addAll(peerList.getDeviceList()); for (WifiP2pDevice device : peers) { getIPFromMac(device.deviceAddress); boolean exists = false; for (String s: successes) { if (s.equals(device.deviceAddress)) { exists = true; break; } } if (exists) continue; else successes.add(device.deviceAddress); WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = device.deviceAddress; config.wps.setup = WpsInfo.PBC; manager.connect(channel, config, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { //The intent P2P_CONNECTION_CHANGED.. will notify us. //This can be ignored. Log.d("Manager.connect", "Successful connection"); try { Thread.sleep(1000); } catch (Exception e) { } } @Override public void onFailure(int reason) { //TODO error handle (maybe?) Log.d("Manager.connect", "connect failed " + reason); } }); //new ClientThread(this, getIPFromMac(device.deviceAddress)).start(); } }
public void connect(String deviceAddress) { WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = deviceAddress; config.wps.setup = WpsInfo.PBC; manager.connect(channel, config, new InfoActionListener("Connecting", "Connection Error", this)); }
public void connect() { WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = ScreenMAC; config.wps.setup = WpsInfo.PBC; manager.connect(channel, config, new InfoActionListener("Connecting", "Connection Error", this)); }
public void connect(String deviceAddress){ WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = deviceAddress; config.wps.setup = WpsInfo.PBC; manager.connect(channel, config, new ActionListener() { public void onSuccess() { // TODO Auto-generated method stub } public void onFailure(int reason) { // TODO Auto-generated method stub } }); }
public void connect(){ WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress = wfDevice.deviceAddress; config.wps.setup = WpsInfo.PBC; wfManager.connect(wfChannel, config, new WifiP2pManager.ActionListener(){ @Override public void onSuccess(){ Log.d(TAG, "Connection initiation succeeded..."); } @Override public void onFailure(int reason){ Log.d(TAG, "Connection initiation failed..."); } }); }