I have an Android app to which I am trying to add DNS SRV record detection. I know it is possible, based on the existence of apps such as DNS Lookup, which I have installed, and it works just fine.
I am using dnsjava and this code runs fine as a stand-alone Java application on my machine, but when I run it on my Android device, I just get the "Error!" message:
Lookup lookup = new Lookup(serviceName, Type.SRV, DClass.IN);
Resolver resolver = new SimpleResolver();
lookup.setResolver(resolver);
lookup.setCache(null);
Record[] records = lookup.run();
if (lookup.getResult() == Lookup.SUCCESSFUL) {
String responseMessage = null;
String listingType = null;
for (int i=0; i < records.length; i++) {
if (records[i] instanceof SRVRecord) {
listingType = ((SRVRecord) records[i]).toString()
}
}
System.out.println("Found!");
System.out.println("Response Message: "+responseMessage);
System.out.println("Listing type: "+listingType);
} else if (lookup.getResult() == Lookup.HOST_NOT_FOUND) {
System.out.println("Not found.");
} else {
System.out.println("Error!");
}
Any ideas why this isn't working?