Android Studio: getScanResults returns empty but permission is given

前端 未结 2 574
失恋的感觉
失恋的感觉 2021-01-12 11:18

I am trying to create a code that returns me available Wi-Fi networks. But I am facing a problem. getScanResults returns empty, though I have given all possible network perm

2条回答
  •  [愿得一人]
    2021-01-12 11:39

    Starting from Android 6, you have to enable location services in order to get desired results. Granting permissions is just the half work done.

    You can also fire an intent to redirect user to this setting:

    Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivity(myIntent);
    

    Location services are necessary because when you access the scan results, you can access the information like BSSID (address of the access point). This information can also be used to detect the location of device. By requiring location services, OS ensures that user understands their location information is being accessed when they use your app.

提交回复
热议问题