-1

I wrote an app that detects wifi networks and when I press on a network it gives me detailed info about that network. Now the problem is that I wrote it 3 years ago when Android KitKat did not require the popup permission from the user and now when I run it on android N and I press scan it neither scans nor gives me the pop-up permission.

I have not programmed android for a long time and I don't know the changes in Android app coding requirements . Any ideas why this happens?

Current permissions used by the app:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
Ahmed Nageeb
  • 121
  • 1
  • 9

1 Answers1

2

In order to get WiFi scan results on Marshmallow and later, your app will need to request the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, and the Location Mode setting must be enabled as well.

From the documentation for getScanResults():

the list of access points found in the most recent scan. An app must hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in order to get valid results

This change was made due to the fact that location can be determined from WiFi scan results.

As an extra security measure, apps now need to request the Location permission in order to see WiFi scan results, and additionally if the user sets their Location Mode to off, no app can see scan results when running in the background.

So, at a bare minimum, add the ACCESS_COARSE_LOCATION permission to your manifest in order to get WiFi scan results:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

If you keep your target API version lower than 23, you can't request permissions at runtime. In this case, your app will continue to request all permissions at install time.

If you update your app to target API version 23 or later, you will need to request all dangerous permissions at runtime. See here for an example of requesting the Location permission at runtime.

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137