public ARDiscoveryMdnsSdMinDiscovery(Set<ARDISCOVERY_PRODUCT_ENUM> supportedProducts) { ARSALPrint.v(TAG, "Creating MdsnSd based ARDiscovery"); // build the list of services to look for devicesServices = new HashMap<String, ARDISCOVERY_PRODUCT_ENUM>(); for (int i = ARDISCOVERY_PRODUCT_ENUM.ARDISCOVERY_PRODUCT_NSNETSERVICE.getValue(); i < ARDISCOVERY_PRODUCT_ENUM.ARDISCOVERY_PRODUCT_BLESERVICE.getValue(); ++i) { if (supportedProducts.contains(ARDISCOVERY_PRODUCT_ENUM.getFromValue(i))) { String devicesService = String.format( ARDiscoveryService.ARDISCOVERY_SERVICE_NET_DEVICE_FORMAT, ARDiscoveryService.nativeGetProductID(i)); devicesService += ARDiscoveryService.ARDISCOVERY_SERVICE_NET_DEVICE_DOMAIN; devicesServices.put(devicesService, ARDISCOVERY_PRODUCT_ENUM.getFromValue(i)); } } netDeviceServicesHmap = new HashMap<String, ARDiscoveryDeviceService>(); mdnsSd = new MdnsSdMin( devicesServices.keySet().toArray(new String[devicesServices.keySet().size()]), mdsnSdListener); // create the connectivity change receiver networkStateChangedFilter = new IntentFilter(); networkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); }
@Override public void onServiceAdded( String name, String serviceType, String ipAddress, int port, String[] txts) { ARSALPrint.d( TAG, "onServiceAdded : " + name + " |type : " + serviceType + " |ip : " + ipAddress + " |port : " + port + " |txts = " + txts); String serialNumber = null; if (txts != null && txts.length >= 1) { serialNumber = txts[0]; } ARDiscoveryDeviceNetService deviceNetService = new ARDiscoveryDeviceNetService(name, serviceType, ipAddress, port, serialNumber); ARDISCOVERY_PRODUCT_ENUM product = devicesServices.get(deviceNetService.getType()); if (product != null) { int productID = ARDiscoveryService.nativeGetProductID(product.getValue()); ARDiscoveryDeviceService deviceService = new ARDiscoveryDeviceService(name, deviceNetService, productID); netDeviceServicesHmap.put(deviceService.getName(), deviceService); if (broadcaster != null) { // got an answer, stop sending queries mdnsSd.cancelSendQueries(); // broadcast the new deviceServiceList broadcaster.broadcastDeviceServiceArrayUpdated(); } } }