Android Studio: getScanResults returns empty but permission is given

前端 未结 2 556
失恋的感觉
失恋的感觉 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:31

    If you are using it on a device with Android 6 or higher you have to enable location services to get the scan results, even if you have the right permissions.

    For more information see here: https://stackoverflow.com/a/32151901/6951450

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题