WifiP2pManager.discoverPeers fails in android 10

Viewed 1283

following code sample returns Error code: 0, which is the error code for internal error in android. Is there any workaround which can enable discovering peers in android 10 devices?

                wifip2pmanager.discoverPeers(wifip2pmanagerChannel, new WifiP2pManager.ActionListener() {
                @Override
                public void onSuccess() {
                    status.setText("Peer Discovery Started");
                }

                @Override
                public void onFailure(int reason) {

                    status.setText("Error code:" + reason);
                }
            });
2 Answers

Exactly the same happened to me...

ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION are not enough. The user has to explcitly activate the location services! (in my case turning on location solved the problem...)

This means: Either you activate location in your settings manually or you make a usability friendly request to the user to activate location services (looks similar to permission request window; see google maps)

See this question for example code of the latter. Hope this helps!

Edit: If you search for an anwser that not envolves any Google libs, see the anwser to this question.

In addition to the statement in the list, you also need to dynamically apply for this permission.

Related