NearbyConnections API startDiscovery always failed
supervital opened this issue · 3 comments
Hello,
After some time of testing Nearby Connections API, I faced the case when startDiscovery() is always failed with error code 8034: MISSING_PERMISSION_ACCESS_COARSE_LOCATION. But all the permissions are granted. At the same time startAdvertising() works like a charm (same app, same granted permissions). The Nearby worked well but after some time startDiscovery() started to fail. Looks like it's an API bug. Used strategy - Strategy.P2P_POINT_TO_POINT.
Example application (Rock-Paper-Scissors) also failed. I changed the example a bit - one device is Discovering, another Advertising.
Have no idea how to fix it.
Thanks.
I found the reason when startDiscovery() is always failed - the Location option from the Android Setting was turned off manually. I supposed that the Nearby Connections API should turn on all the necessary options and turn them off after the session.
Looks like I should turn Location settings on programmatically. Smells bad(
Hi supervital,
Sorry to hear about your experience. Location is a dangerous permission and therefore only the user can turn it on. As a developer, you must declare it in your manifest and you must request it at runtime. We recently published a codelab that walks you through using the Nearby Connections API. Please take a look there for more details.
Best,
Isai