Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List Wifi without enabling location service

While developing an app where I scan the WiFi, I found that it does not work if I turn off the location service on my phone. I have provided the app with all the necessary permissions. - ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION.

This is my code:

WifiManager manager= (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
manager.startScan();

In the receiver:

int found = manager.getScanResults().size();

This question answers part of the problem. Wifi scan results broadcast receiver not working

My questions are:

  1. Is there a way for the app to list the Wifi access points if the location service is turned off?

  2. If location service is absolutely necessary, is there a way for the app to turn on the location service while the app scans the wifi access points?

like image 417
sudhir shakya Avatar asked Oct 25 '25 20:10

sudhir shakya


1 Answers

The only way to get the scanResult without GPS turned on is to set the app's targetSDKversion to 21 or lower.

This will work even on Lolipop and above.

like image 119
lakshman.pasala Avatar answered Oct 28 '25 12:10

lakshman.pasala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!