Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
Do not try to start NSD service if it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
velitasali committed Apr 18, 2018
1 parent 74c9269 commit 8d9759e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/src/main/java/com/genonbeta/TrebleShot/util/NsdDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,23 @@ public void registerService()
localServiceInfo.setServiceType(AppConfig.NDS_COMM_SERVICE_TYPE);
localServiceInfo.setPort(AppConfig.SERVER_PORT_COMMUNICATION);

getNsdManager().registerService(localServiceInfo, NsdManager.PROTOCOL_DNS_SD, getRegistrationListener());
try {
getNsdManager().registerService(localServiceInfo, NsdManager.PROTOCOL_DNS_SD, getRegistrationListener());
} catch (Exception e) {
e.printStackTrace();
}
}
}

public void startDiscovering()
{
if (isServiceEnabled()
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
getNsdManager().discoverServices(AppConfig.NDS_COMM_SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, getDiscoveryListener());
try {
getNsdManager().discoverServices(AppConfig.NDS_COMM_SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, getDiscoveryListener());
} catch (Exception e) {
e.printStackTrace();
}
}

public void stopDiscovering()
Expand All @@ -193,7 +201,7 @@ public void stopDiscovering()
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
try {
getNsdManager().stopServiceDiscovery(getDiscoveryListener());
} catch (IllegalArgumentException e) {
} catch (Exception e) {
// Listener may not have been initialized
}
}
Expand All @@ -204,7 +212,7 @@ public void unregisterService()
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
try {
getNsdManager().unregisterService(getRegistrationListener());
} catch (IllegalArgumentException e) {
} catch (Exception e) {
// Listener may not have been initialized
}
}
Expand Down

0 comments on commit 8d9759e

Please sign in to comment.