类android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo源码实例Demo

下面列出了怎么用android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Salut   文件: Salut.java
@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;
        }
    });
}
 
 类所在包
 类方法
 同包方法