Reputation: 157
I've been working with the Android WifiP2pManager to discover specific services on other devices. I'm wondering if there is a known timeout period for the function
public void discoverServices (WifiP2pManager.Channel c, WifiP2pManager.ActionListener listener)
I can't find any resources on it in the Android API. I'm aware that I can set a listener for a successful discovery, but I don't know how to tell if no discovery has been made.
Additionally, is there any way to stop discovery without entirely stopping the wifi manager's functionality?
Thanks in advance for any help!
Upvotes: 2
Views: 943
Reputation: 4917
For the timeout is 2 minutes as mentionned in Android documentation :
// We repeatedly issue calls to discover peers every so often for a few reasons.
// 1. The initial request may fail and need to retried.
// 2. Discovery will self-abort after any group is initiated, which may not necessarily
// be what we want to have happen.
// 3. Discovery will self-timeout after **2 minutes**, whereas we want discovery to
// be occur for as long as a client is requesting it be.
// 4. We don't seem to get updated results for displays we've already found until
// we ask to discover again, particularly for the isSessionAvailable() property.
Upvotes: 0
Reputation: 2630
https://sphen.proxmobil.com/android-wi-fi-direct-service-discovery/
This blog mentioned the timeout is 120 seconds.
Service discovery will only last for 120 seconds from the time the discoverServices method of WifiP2pManager is called. If application developers require service discovery for a longer period, they will need to re-call the WifiP2pManager.discoverServices method.
Upvotes: 0
Reputation: 2396
As far as I know the clearServiceRequests() should work fine for cancelling service discovery.
In general I have also not found any docs for timeout, thus I have been using 1 minute timeout timer to fix the issue.
Notice though that you should cancel the timeout timer once you have gotten the callback called once, after that you should just wait for new services being discovered.
I have also not seen any docs for how long the service discovery timeout should be between different services, but with some testing I have determined that it should be at least 5 seconds, in order to get services available discovered nicely.
Upvotes: 1