Skip to content

Instantly share code, notes, and snippets.

@molidev8
Created June 9, 2022 14:07
Show Gist options
  • Save molidev8/76a3de9d87d68804f81371068f84d4d3 to your computer and use it in GitHub Desktop.
Save molidev8/76a3de9d87d68804f81371068f84d4d3 to your computer and use it in GitHub Desktop.
A function to act as a subscriber in Nearby Share
fun startDiscovering() {
val discoveryOptions =
DiscoveryOptions.Builder().setStrategy(Strategy.P2P_POINT_TO_POINT).build()
client
.startDiscovery(SERVICE_ID, object : EndpointDiscoveryCallback() {
override fun onEndpointFound(endPointId: String, info: DiscoveredEndpointInfo) {
client.requestConnection(android.os.Build.MODEL, endPointId, ConnectingProcessCallback())
.addOnSuccessListener {
}
.addOnFailureListener {
}
}
override fun onEndpointLost(endPointId: String) {
Log.d(GENERAL, "endpoint lost")
}
}, discoveryOptions)
.addOnSuccessListener { Log.d(GENERAL, "discovering...") }
.addOnFailureListener {
Log.d(GENERAL, "failure discovering...")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment