diff --git a/app/src/main/java/com/genonbeta/TrebleShot/util/NsdDiscovery.java b/app/src/main/java/com/genonbeta/TrebleShot/util/NsdDiscovery.java index abcb0fe4..fc7bf28e 100644 --- a/app/src/main/java/com/genonbeta/TrebleShot/util/NsdDiscovery.java +++ b/app/src/main/java/com/genonbeta/TrebleShot/util/NsdDiscovery.java @@ -176,7 +176,11 @@ 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(); + } } } @@ -184,7 +188,11 @@ 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() @@ -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 } } @@ -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 } }