Java Code Examples for

The following examples show how to use These examples are extracted from open source projects. 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 Project: Salut   Source File:    License: MIT License 5 votes vote down vote up
private void createService(final SalutCallback onSuccess, final SalutCallback onFailure) {

    manager.clearLocalServices(channel, null);

    Log.d(TAG, "Starting " + thisDevice.serviceName + " Transport Protocol " + TTP);

    //Inject the listening port along with whatever else data that is going to be sent.
    thisDevice.txtRecord.put("LISTEN_PORT", String.valueOf(thisDevice.servicePort));

    //Create a service info object will android will actually hand out to the clients.
    serviceInfo = WifiP2pDnsSdServiceInfo.newInstance(thisDevice.instanceName, TTP, thisDevice.txtRecord);

    //Register our service. The callbacks here just let us know if the service was registered correctly,
    //not necessarily whether or not we connected to a device.
    manager.addLocalService(channel, serviceInfo, new WifiP2pManager.ActionListener() {
        public void onSuccess() {
            Log.v(TAG, "Successfully added the local service.");
            if (onSuccess != null)


        public void onFailure(int error) {
            Log.e(TAG, "Failed to create " + thisDevice.serviceName + " : Error Code: " + error);
            if (onFailure != null)
            isRunningAsHost = false;