use of android.net.nsd.NsdManager in project facebook-android-sdk by facebook.
the class DeviceRequestsHelper method cleanUpAdvertisementServiceImpl.
@TargetApi(16)
private static void cleanUpAdvertisementServiceImpl(String userCode) {
NsdManager.RegistrationListener nsdRegistrationListener = deviceRequestsListeners.get(userCode);
if (nsdRegistrationListener != null) {
NsdManager nsdManager = (NsdManager) FacebookSdk.getApplicationContext().getSystemService(Context.NSD_SERVICE);
nsdManager.unregisterService(nsdRegistrationListener);
deviceRequestsListeners.remove(userCode);
}
}
use of android.net.nsd.NsdManager in project facebook-android-sdk by facebook.
the class DeviceRequestsHelper method startAdvertisementServiceImpl.
@TargetApi(16)
private static boolean startAdvertisementServiceImpl(final String userCode) {
if (deviceRequestsListeners.containsKey(userCode)) {
return true;
}
// Dots in the version will mess up the Bonjour DNS record parsing
String sdkVersion = FacebookSdk.getSdkVersion().replace('.', '|');
// Other SDKs that adopt this feature should use different flavor name
// The whole name should not exceed 60 characters
final String nsdServiceName = String.format("%s_%s_%s", // static identifier
SDK_HEADER, // client app parses the string based on this version
String.format("%s-%s", SDK_FLAVOR, sdkVersion), // short code for the login flow
userCode);
NsdServiceInfo nsdLoginAdvertisementService = new NsdServiceInfo();
nsdLoginAdvertisementService.setServiceType(SERVICE_TYPE);
nsdLoginAdvertisementService.setServiceName(nsdServiceName);
nsdLoginAdvertisementService.setPort(80);
NsdManager nsdManager = (NsdManager) FacebookSdk.getApplicationContext().getSystemService(Context.NSD_SERVICE);
NsdManager.RegistrationListener nsdRegistrationListener = new NsdManager.RegistrationListener() {
@Override
public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) {
// Android may have changed the service name in order to resolve a conflict
if (!nsdServiceName.equals(NsdServiceInfo.getServiceName())) {
cleanUpAdvertisementService(userCode);
}
}
@Override
public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
}
@Override
public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
cleanUpAdvertisementService(userCode);
}
@Override
public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) {
}
};
deviceRequestsListeners.put(userCode, nsdRegistrationListener);
nsdManager.registerService(nsdLoginAdvertisementService, NsdManager.PROTOCOL_DNS_SD, nsdRegistrationListener);
return true;
}
Aggregations