cordova-plugin-zeroconf icon indicating copy to clipboard operation
cordova-plugin-zeroconf copied to clipboard

zeroconf.watch not working on Android 9

Open sevicbb opened this issue 5 years ago • 3 comments

zeroconf.watch('_http._tcp.', 'local.', ({ action, service }) => {
    console.log(service)
    if (action === "resolved") {
      console.log(service)
    } else if (action === "removed") {
      console.log(service)
    }
})

Same code works on iOS. It was working on Android but suddenly it stopped. Any suggestions? Getting this error in failure callback:

Error: Attempt to invoke interface method 'boolean java.util.Enumeration.hasMoreElements()' on a null object reference

sevicbb avatar May 19 '20 11:05 sevicbb

The error line appears to be here: https://github.com/becvert/cordova-plugin-zeroconf/blob/master/src/android/net/becvert/cordova/ZeroConf.java#L555

        Enumeration<String> names = service.getPropertyNames();
        while (names.hasMoreElements()) {

I suppose the service.getPropertyNames() method is returning an unexpected result. A solution might be just to try/catch this call. We should also look at service that gets passed into jsonifyService(ServiceInfo service) too, it could be that service itself is empty and doesn't have any propertyNames to iterate. The mystery then becomes "what kind of service was returned from registrationManager.register() that is invalid?

Does Android 9 change or update app permission structures?

emcniece avatar Aug 31 '20 15:08 emcniece

Does anyone have a clue on how to resolve this? It's also not working on Android 11. Are there any alternative plugins to obtain local network devices?

SamuelMichelRiad avatar May 28 '21 21:05 SamuelMichelRiad

Yes, as per my previous comment, https://github.com/becvert/cordova-plugin-zeroconf/blob/master/src/android/net/becvert/cordova/ZeroConf.java#L555 needs error handling and investigation. Apologies, I don't have capacity to do this at the moment :(

emcniece avatar May 29 '21 14:05 emcniece