Example usage for android.net.wifi.p2p WifiP2pConfig WifiP2pConfig

List of usage examples for android.net.wifi.p2p WifiP2pConfig WifiP2pConfig

Introduction

In this page you can find the example usage for android.net.wifi.p2p WifiP2pConfig WifiP2pConfig.

Prototype

public WifiP2pConfig() 

Source Link

Usage

From source file:com.example.ramesh.p2pfileshare.ClientActivity.java

public void connectToPeer(final WifiP2pDevice wifiPeer) {
    this.targetDevice = wifiPeer;

    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = wifiPeer.deviceAddress;
    wifiManager.connect(wifichannel, config, new WifiP2pManager.ActionListener() {
        public void onSuccess() {

            setClientStatus("Connection to " + targetDevice.deviceName + " sucessful");

            sendFileButton.setVisibility(View.VISIBLE);

        }/*from  w ww .  j a  v a2  s  . co  m*/

        public void onFailure(int reason) {
            setClientStatus("Connection to " + targetDevice.deviceName + " failed");

        }
    });

}

From source file:it.polimi.deib.p2pchat.discovery.chatmessages.waitingtosend.discovery.MainActivity.java

/**
 * Method that connects to the specified service.
 *
 * @param service The {@link WiFiP2pService}
 *                to which you want to connect.
 *///ww w  . j ava  2  s. c  o m
private void connectP2p(WiFiP2pService service) {
    Log.d(TAG, "connectP2p, tabNum before = " + tabNum);

    if (DestinationDeviceTabList.getInstance().containsElement(new P2pDestinationDevice(service.getDevice()))) {
        this.tabNum = DestinationDeviceTabList.getInstance()
                .indexOfElement(new P2pDestinationDevice(service.getDevice())) + 1;
    }

    if (this.tabNum == -1) {
        Log.d("ERROR", "ERROR TABNUM=-1"); //only for testing purposes.
    }

    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = service.getDevice().deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    config.groupOwnerIntent = 10; //because i want that this device is the Server.

    if (serviceRequest != null) {
        manager.removeServiceRequest(channel, serviceRequest, new CustomizableActionListener(MainActivity.this,
                "connectP2p", null, "RemoveServiceRequest success", null, "removeServiceRequest failed"));
    }

    manager.connect(channel, config, new CustomizableActionListener(MainActivity.this, "connectP2p", null,
            "Connecting to service", null, "Failed connecting to service"));
}

From source file:com.prgpascal.qrdatatransfer.TransferActivity.java

/**
 * Connect to the desired peer.//from www  .j  ava 2 s  .com
 *
 * @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();
        }
    });
}

From source file:com.nest5.businessClient.Initialactivity.java

@Override
public void showDetails(WifiP2pDevice device) {
    Toast.makeText(mContext, "Conectando con: " + device.deviceName, Toast.LENGTH_SHORT).show();
    isConnecting = true;/*from   w w w. ja  v a 2 s. c o  m*/
    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;
    statusText.setText("Conectando con: " + device.deviceName);

    connect(config);

}