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); } }); }
@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(); } }); }
@Override public void disconnect() { final DeviceDetailFragment fragment = (DeviceDetailFragment) getFragmentManager() .findFragmentById(R.id.frag_detail); fragment.resetViews(); manager.removeGroup(channel, new ActionListener() { @Override public void onFailure(int reasonCode) { Log.d(TAG, "Disconnect failed. Reason :" + reasonCode); } @Override public void onSuccess() { fragment.getView().setVisibility(View.GONE); } }); }
@Override protected void onStop() { if (manager != null && channel != null) { manager.removeGroup(channel, new ActionListener() { @Override public void onFailure(int reasonCode) { Log.d(TAG, "Disconnect failed. Reason :" + reasonCode); } @Override public void onSuccess() { } }); } super.onStop(); }
/** * Registers a local service and then initiates a service discovery */ private void startRegistrationAndDiscovery() { Map<String, String> record = new HashMap<String, String>(); record.put(TXTRECORD_PROP_AVAILABLE, "visible"); WifiP2pDnsSdServiceInfo service = WifiP2pDnsSdServiceInfo.newInstance( SERVICE_INSTANCE, SERVICE_REG_TYPE, record); manager.addLocalService(channel, service, new ActionListener() { @Override public void onSuccess() { appendStatus("Added Local Service"); } @Override public void onFailure(int error) { appendStatus("Failed to add a service"); } }); discoverService(); }
/** * Issue a request to the WifiP2pManager to start discovering peers. * This is an internal method. To turn on/off peer discovery from higher * level application code, call setSeekingDesired(true/false). */ private void seekPeers() { // DO NOT SUBMIT // Switched this to be && if (!getSeeking() && lastSeekingWasLongAgo()) { setSeeking(true); touchLastSeekingTime(); stopwatch.reset(); stopwatch.start(); mWifiP2pManager.discoverPeers(mWifiP2pChannel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.d(TAG, "Discovery initiated"); } @Override public void onFailure(int reasonCode) { Log.d(TAG, "Discovery failed: " + reasonCode); setSeeking(false); stopSeekingPeers(); } }); } else { Log.v(TAG, "Attempted to seek peers while already seeking, not doing it."); } }
/** * Issue a request to the WifiP2pManager to stop discovering peers. * This is an internal method. To turn on/off peer discovery from higher * level application code, call setSeekingDesired(true/false). */ private void stopSeekingPeers() { if(getSeeking()) { log.info("Stopped seeking peers"); Log.d("peerDebug","Stopped seeking peers"); mWifiP2pManager.stopPeerDiscovery(mWifiP2pChannel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { log.debug("Discovery stopped successfully."); setSeeking(false); } @Override public void onFailure(int reasonCode) { log.debug("Failed to stop peer discovery? Reason: " + reasonCode); } }); } }
public void discoverDevice() { Log.d(TAG, "WifiP2pHelper-->discoverDevice()"); if (!isWifiOn()) { toggleWifi(true); } if (isConnected) { Log.d(TAG, "WifiP2pHelper-->discoverDevice ended-->isConnected=true"); return; } handler.sendEmptyMessage(WIFIP2P_DEVICE_DISCOVERING); manager.discoverPeers(channel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { } @Override public void onFailure(int reasonCode) { Log.d(TAG, "WifiP2pHelper-->discoverDevice failed reasonCode=" + reasonCode); } }); }
public void release() { Log.d(TAG, "WifiP2pHelper-->release()"); try { this.serverSocket.close(); } catch (Exception e) { } if(fileReceiveAsyncTask!=null) { fileReceiveAsyncTask.cancel(true); } if(fileSendAsyncTask!=null) { fileSendAsyncTask.cancel(true); } manager.removeGroup(channel, new ActionListener() { @Override public void onFailure(int reasonCode) { Log.d(TAG, "Disconnect failed. Reason :" + reasonCode); } @Override public void onSuccess() { } }); }
/** * 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(); } }); }
/** Disconnect from Wifi Direct. */ private void disconnect() { // Now I'm disconnected. isConnected = false; // Remove this Wifi Direct group. manager.removeGroup(channel, new ActionListener() { @Override public void onFailure(int reasonCode) { Log.d(DEBUG_TAG, "Disconnect failed. Reason :" + reasonCode); } @Override public void onSuccess() { Log.d(DEBUG_TAG, "Disconnected and group removed"); } }); }
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 disconnectP2p(){ Log.d(TAG,"inside disconnectP2p "); if (manager != null && channel != null) { manager.removeGroup(channel, new ActionListener() { @Override public void onFailure(int reasonCode) { Log.d(TAG, "Disconnect failed. Reason :" + reasonCode); } @Override public void onSuccess() { Log.d(TAG, "Disconnect sucessful."); } }); } p2pconnected=false; }
/** * 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"); } }); }
public void startDiscovery(){ if (!isWifiP2pEnabled) { Toast.makeText(WiFiDirectActivity.this, R.string.p2p_off_warning, Toast.LENGTH_SHORT).show(); return; } fragmentList.onInitiateDiscovery(); manager.discoverPeers(channel, new ActionListener() { public void onSuccess() { Toast.makeText(WiFiDirectActivity.this, "Discovery Initiated", Toast.LENGTH_SHORT).show(); } public void onFailure(int reasonCode) { Toast.makeText(WiFiDirectActivity.this, "Discovery Failed : " + reasonCode, Toast.LENGTH_SHORT).show(); fragmentList.cancelDiscovery(); } }); }
private void addServiceRequest() { WifiP2pDnsSdServiceRequest request = WifiP2pDnsSdServiceRequest.newInstance(); final Handler handler = new Handler(); p2p.addServiceRequest(channel, request, new ActionListener() { public void onSuccess() { Log.d(TAG, "Added service request"); // Calling discoverServices() too soon can result in a // NO_SERVICE_REQUESTS failure - looks like a race condition // http://p2feed.com/wifi-direct.html#bugs handler.postDelayed(new Runnable() { public void run() { startServiceDiscovery(); } }, 1000); } public void onFailure(int reason) { print("Adding service request failed, error code " + reason); // No point starting service discovery } }); }
public void deinit() { mContext.unregisterReceiver(mNFGameBroadcastReceiver); mWifiP2pManager.clearLocalServices(mChannel, new NFGameActionListener("clearLocalServices")); mWifiP2pManager.clearServiceRequests(mChannel, new NFGameActionListener("clearServiceRequests")); stopPeerDiscovery(); mWifiP2pManager.cancelConnect(mChannel, new NFGameActionListener("cancelConnect")); mWifiP2pManager.removeGroup(mChannel, new NFGameActionListener("removeGroup")); if (mNetId != -1) { try { Method deletePersistentGroup = mWifiP2pManager.getClass().getMethod("deletePersistentGroup", Channel.class, int.class, ActionListener.class); deletePersistentGroup.setAccessible(true); deletePersistentGroup.invoke(mWifiP2pManager, mChannel, mNetId, new NFGameActionListener("deletePersistentGroup")); } catch (Exception e) { e.printStackTrace(); } } }
public void setAdvertisement() { mRecordMap.put(PORT, Integer.toString(mPort)); mRecordMap.put(IDENTIFIER, myIdentifier); mInfo = WifiP2pDnsSdServiceInfo.newInstance(instanceNamePrefix + myIdentifier, SERVICE_TYPE, mRecordMap); mManager.addLocalService(mChannel, mInfo, new ActionListener() { @Override public void onSuccess() { WfdLog.d(TAG, "addLocalService success"); } @Override public void onFailure(int reason) { Log.e(TAG, "addLocalService failure: " + reason); } }); }
@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(); } }); }
@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 setupDnsSdServiceRequest() { if (serviceRequest == null){ // After attaching listeners, create a service request for the type of service desired serviceRequest = WifiP2pDnsSdServiceRequest.newInstance(); manager.addServiceRequest(channel, serviceRequest, new ActionListener() { public void onSuccess() { // appendStatus("Added service discovery request"); } public void onFailure(int reason) { // appendStatus("Failed adding service discovery request"); } }); } }
/** * Disconnect all related to this WifiP2p Connection */ public void disconnect() { if (manager != null && channel != null) { manager.removeGroup(channel, new ActionListener() { public void onFailure(int reasonCode) { Log.d("WifiDirectManager", "Disconnect failed. Reason :" + reasonCode); } public void onSuccess() { } }); } }
public void searchPeer(){ mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { return; } @Override public void onFailure(int reasonCode) { showMessage("Search Failed: "+ reasonCode); // Toast.makeText(CONTEXT, "Search Failed: "+reasonCode,Toast.LENGTH_SHORT).show(); return; } }); }
@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; }
@Override public void disconnect() { // TODO Auto-generated method stub final DeviceDetailFragment fragment = (DeviceDetailFragment) getFragmentManager() .findFragmentById(R.id.devicedetail); fragment.resetViews(); mManager.removeGroup(mChannel, new ActionListener() { @Override public void onFailure(int reasonCode) { showMessage("Disconnect failed. Reason :" + reasonCode); } @Override public void onSuccess() { // fragment.getView().setVisibility(View.GONE); showMessage("Disconnected."); } }); }
@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(); } }); }
@Override public void disconnect() { mSocketService.sendHandShakeDisconnect(); mManager.removeGroup(mChannel, new ActionListener() { @Override public void onFailure(int reasonCode) { Log.e(TAG, "Disconnect failed. Reason :" + reasonCode); } @Override public void onSuccess() { } }); }
private void discoverPeers() { /** * discover other devices */ Log.i(TAG, "discoverPeers"); manager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() { @Override public void onSuccess() { Log.i(TAG, "discoverPeers success"); Toast.makeText(getActivity(), "Discovery Initiated", Toast.LENGTH_SHORT).show(); } @Override public void onFailure(int reasonCode) { Log.i(TAG, "discoverPeers fail"); Toast.makeText(getActivity(), "Discovery Failed : " + reasonCode, Toast.LENGTH_SHORT) .show(); // if (progressDialog != null && progressDialog.isShowing()) { // progressDialog.dismiss(); // } } }); }