I’m working on an app that will scan devices on a network using the Cling application. I have tried to modify it so that I am able to see the IP address of the devices too using the getBaseURL method. However when I scan devices, some of them show up with an IP and the others return null. Is there any way to sort this out?
@Override
public String toString() {
String name =
device.getDetails() != null && device.getDetails().getFriendlyName() != null
? device.getDetails().getFriendlyName() +device.getDetails().getBaseURL()
: device.getDisplayString();
Interestingly enough,
org.teleal.cling.model.meta.DeviceDetailshas many constructors, but only two types: ones which getfriendlyNamebut nobaseURL(hence it is left null) and other (only two) which get both.baseURLis final private, so no chance you could set it afterwards. I personally don’t understand the design decision (why a knowledge offriendlyNameis considered superseding the knowledge ofbaseURL) but IMO there lies the problem. Put a breakpoint in the last constructor ofDeviceDetails(the only one which sets the private members) and observe, from where it is being called (and through which specific constructor overload). Every UPnP device has a baseURL, it tells it in LOCATION header of its NOTIFY message. So the fact thatDeviceDetailsdoesn’t provide it is an issue of Cling not being interested in it (i.e. not calling the constructor which takes it).