diff --git a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java index 02c0b9662c742c..dbbb9052c710f0 100644 --- a/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java +++ b/src/platform/android/java/chip/platform/NsdManagerServiceResolver.java @@ -127,9 +127,22 @@ public void publish( String[] subTypes) { NsdServiceInfo serviceInfo = new NsdServiceInfo(); serviceInfo.setServiceName(serviceName); - serviceInfo.setServiceType(type); + + /** + * Note, subtypes registration is using an undocumented feature of android dns-sd + * service/mDNSResponder which MAY STOP WORKING in future Android versions. Here, set type = + * "${type},${subtypes1},${subtypes2},...", then subtypes1, subtypes2 etc are all registered to + * this dns-sd server, we can usd `dns-sd -B ${type},${subtypes}` or avahi-browse + * ${subtypes}._sub.${type} -r to browser it + */ + StringBuilder sb = new StringBuilder(type); + for (String subType : subTypes) { + sb.append(",").append(subType); + } + serviceInfo.setServiceType(sb.toString()); + serviceInfo.setPort(port); - Log.i(TAG, "publish serviceName=" + serviceName + " type=" + type + " port=" + port); + Log.i(TAG, "publish serviceName=" + serviceName + " type=" + sb.toString() + " port=" + port); int cnt = Math.min(textEntriesDatas.length, textEntriesKeys.length); for (int i = 0; i < cnt; i++) { String value = new String(textEntriesDatas[i]);