Java源码示例:android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo

示例1
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
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() {
        @Override
        public void onSuccess() {
            Log.v(TAG, "Successfully added the local service.");
            if (onSuccess != null)
                onSuccess.call();

        }

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