Bonjour implementation on Android

后端 未结 5 1195
深忆病人
深忆病人 2020-12-23 10:22

I am trying to implement bonjour/zero conf on my android app. I am using jmDns library for searching the all the available devices. Here is the code that I am using for sear

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 10:54

    As noted in comments above, the native Android support is not working and/or not implemented completely to allow retrieval of TXT records (as of Android v5.1). I also could not get the jmDns library to work for discovery. I finally found the mdnsjava project and it worked very easily for me. Note that its sample code is not correct. Here is some sample of code I used to synchronously find all IPP printers:

        String type[] = {"_ipp._tcp.local."};
        Lookup resolve = null;
        try {
            resolve = new Lookup(type, Type.ANY, DClass.IN);
            ServiceInstance[] records = resolve.lookupServices();
            for (ServiceInstance record : records) {
                Log.d(TAG, record.toString());
                Map txtMap = record.getTextAttributes();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    

    Also note that you need to add the dnsjava library to your libs folder and your build.gradle. I used version 2.1.7.

提交回复
热议问题