5

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);
                }
            });
J.Maduka
  • 73
  • 1
  • 10

2 Answers2

8

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.

luke8800gts
  • 398
  • 3
  • 7
  • Hi, I had asked for both permissions and they ARE allowed when I check app info. Yet I still get reason code 1. (my location is on too) – Lavnish Chaudhary Apr 02 '22 at 17:25
2

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

Ambrose
  • 21
  • 1