android.net.wifi.p2p.WifiP2pConfig Java Examples

The following examples show how to use android.net.wifi.p2p.WifiP2pConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommCareWiFiDirectActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@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();
        }
    });
}
 
Example #2
Source File: WifiDirectManager.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
public void connect(WifiP2pConfig config) {
		ALog.i(TAG, "connect mWifiP2pManager:" + mWifiP2pManager + ", config:" + config);
		if (mWifiP2pManager != null) {
			mWifiP2pManager.connect(mWifiChannel, config, new ActionListener() {

				@Override
				public void onSuccess() {
					ALog.v(TAG, "connect onSuccess!");
					Message msg = mManagerHandler.obtainMessage(Utilities.MSG_WIFI_CONNECT_SUCCESS);
					mManagerHandler.sendMessage(msg);
				}
				
				@Override
				public void onFailure(int reason) {
					ALog.v(TAG, "connect failed reason:" + reason);
//					Message msg = mManagerHandler.obtainMessage(Utilities.MSG_WIFI_CONNECT_FAILED);
//					if(mManagerHandler.hasMessages(Utilities.MSG_WIFI_CONNECT_FAILED))
//						return;
//					mManagerHandler.sendMessageDelayed(msg, 500);
				}
			});
		}
	}
 
Example #3
Source File: DeviceListFragment.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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);

}
 
Example #4
Source File: P2pReceiver.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
public void connect(WifiP2pDevice device)
{
    WifiP2pConfig config=new WifiP2pConfig();

    config.deviceAddress=device.deviceAddress;
    config.wps.setup= WpsInfo.PBC;

    _wifiP2pManager.connect(_channel, config, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {

        }

        @Override
        public void onFailure(int reason) {

        }
    });
}
 
Example #5
Source File: Salut.java    From Salut with MIT License 6 votes vote down vote up
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. ");
            }
        });
    }
 
Example #6
Source File: WiFiP2pHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 指定した機器へ接続を試みる
 * @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");
	}
}
 
Example #7
Source File: WifiP2PServiceImpl.java    From Wifi-Connect with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void connectDevice(WifiP2pDevice wifiP2pDevice) {
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = wifiP2pDevice.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    config.groupOwnerIntent = 15;
    manager.connect(channel, config, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {}
        @Override
        public void onFailure(int reason) {
            if(wifiP2PConnectionCallback != null) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        wifiP2PConnectionCallback.onPeerConnectionFailure();
                    }
                });
            }
        }
    });
}
 
Example #8
Source File: WifiDirectHandler.java    From WiFi-Buddy with MIT License 6 votes vote down vote up
/**
 * 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());
        }
    });
}
 
Example #9
Source File: WiFiDirectActivity.java    From Demo_Public with MIT License 5 votes vote down vote up
@Override
public void connect(WifiP2pConfig config) {
    mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {
        
        @Override
        public void onSuccess() {
            
        }
        
        @Override
        public void onFailure(int reason) {
            Toast.makeText(WiFiDirectActivity.this, "Connect failed", Toast.LENGTH_SHORT).show();
        }
    });
}
 
Example #10
Source File: WiFiP2PCommand.java    From nfcspy with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void executeImp(WiFiP2PManager ctx) {

	final WifiP2pConfig config = new WifiP2pConfig();
	config.wps.setup = android.net.wifi.WpsInfo.PBC;
	config.deviceAddress = peer.deviceAddress;
	ctx.wifip2p.connect(ctx.channel, config, this);
}
 
Example #11
Source File: PeerActivity.java    From android-p2p with MIT License 5 votes vote down vote up
private void connectPeer(WifiP2pDevice peer) {
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = peer.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    this.Application.P2pHandler.Manager.connect(this.Application.P2pHandler.Channel, config, new WifiP2pManager.ActionListener() {
        @Override
        public void onSuccess() {
            Toast.makeText(PeerActivity.this, "Connecting to peer ...", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onFailure(int reason) {
            Toast.makeText(PeerActivity.this, "Peer connection failed with code " + Integer.toString(reason), Toast.LENGTH_SHORT).show();
        }
    });
}
 
Example #12
Source File: WiFiP2pHelper.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * 指定した機器へ接続を試みる
 * @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);
}
 
Example #13
Source File: WiFiP2pHelper.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * 指定した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);
}
 
Example #14
Source File: P2pManager.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
public void connect(WifiP2pDevice device,WifiP2pManager.ActionListener listener)
{
    WifiP2pConfig config=new WifiP2pConfig();

    config.deviceAddress=device.deviceAddress;
    config.wps.setup= WpsInfo.PBC;

    _wifiP2pManager.connect(_channel, config, listener);
}
 
Example #15
Source File: WifiDirectManager.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
public void wifiP2pConnect() {
	ALog.i(TAG, "wifiP2pConnect mRemoteWifiP2pDeviceAddress:" + mRemoteWifiP2pDeviceAddress);
	WifiP2pConfig config = new WifiP2pConfig();
	config.deviceAddress = mRemoteWifiP2pDeviceAddress;
	config.wps.setup = WpsInfo.PBC;
}
 
Example #16
Source File: WiFiDirectActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
private void connectTo(WifiP2pDevice peerDevice) {
  WifiP2pConfig config = new WifiP2pConfig();
  config.deviceAddress = peerDevice.deviceAddress;
  mWifiP2pManager.connect(mWifiDirectChannel, config, actionListener);
}
 
Example #17
Source File: DeviceListFragment.java    From Demo_Public with MIT License votes vote down vote up
void connect(WifiP2pConfig config); 
Example #18
Source File: DeviceListFragment.java    From commcare-android with Apache License 2.0 votes vote down vote up
void connect(WifiP2pConfig config);