Near icon indicating copy to clipboard operation
Near copied to clipboard

Can makeDiscoverable by service like NSD?

Open hienlt0610 opened this issue 4 years ago • 2 comments

I have a lot of devices and I want to group them by service, can you do it? ex: makeDiscoverable (String hostName, String serviceName);

makeDiscoverable ("My android device", "printer.tcp");

Look for devices that have the "printer.tcp" service registered instead of searching for them all startDiscovery ("printer.tcp")

hienlt0610 avatar Jan 20 '20 01:01 hienlt0610

This doesn't work. But even if it did, everything is searched and then filterd out. (No performance advantage)

And you can build a filter by yourself (e.g. a specific string inside the hostname)

DatL4g avatar Jan 22 '20 09:01 DatL4g

When @adroitandroid creates Release v2.0 you can use it like this:

Kotlin

val nearDiscovery = NearDiscovery.Builder()
.setContext(this)
.setDiscoverableTimeoutMillis(DISCOVERABLE_TIMEOUT_MILLIS)
.setDiscoveryTimeoutMillis(DISCOVERY_TIMEOUT_MILLIS)
.setDiscoverablePingIntervalMillis(DISCOVERABLE_PING_INTERVAL_MILLIS)
.setDiscoveryListener(getNearDiscoveryListener(), Looper.getMainLooper())
.setFilter(Regex("printer.tcp")) // shows only devices with parameter "printer.tcp"
.build()

Java

NearDiscovery nearDiscovery = new NearDiscovery.Builder()
.setContext(this)
.setDiscoverableTimeoutMillis(DISCOVERABLE_TIMEOUT_MILLIS)
.setDiscoveryTimeoutMillis(DISCOVERY_TIMEOUT_MILLIS)
.setDiscoverablePingIntervalMillis(DISCOVERABLE_PING_INTERVAL_MILLIS)
.setDiscoveryListener(getNearDiscoveryListener(), Looper.getMainLooper())
.setFilter(Regex("printer.tcp")) // shows only devices with parameter "printer.tcp"
.build()

Setting Parameter

nearDiscovery.makeDiscoverable("hostName", "printer.tcp")

And the issue can be closed then

DatL4g avatar Jan 28 '20 18:01 DatL4g