SCAN_RESULTS_AVAILABLE_ACTION return empty list in Android 6.0 SCAN_RESULTS_AVAILABLE_ACTION return empty list in Android 6.0 android android

SCAN_RESULTS_AVAILABLE_ACTION return empty list in Android 6.0


As of Android 6.0, permission behaviour has changed to runtime. To use a feature that requires a permission, one should check first if the permission is granted previously. Using checkSelfPermission(permissionString) method a result is returned, wither ther permission is PERMISSION_GRANTED or PERMISSION_DENIED.

If permission isn't granted or it is first time, a request for permission should be made. Giving a user an option to grant or deny.

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED){   requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},                 PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION);    //After this point you wait for callback in onRequestPermissionsResult(int, String[], int[]) overriden method}else{    getScanningResults();   //do something, permission was previously granted; or legacy device}

If your code is running on device prior to M, you proceed with your code, permission was granted using legacy method.

Once requested for permission, dialog will be shown to user. His/her response will be delivered as:

@Override public void onRequestPermissionsResult(int requestCode, String[] permissions,         int[] grantResults) {     if (requestCode == PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION             && grantResults[0] == PackageManager.PERMISSION_GRANTED) {         // Do something with granted permission        mWifiListener.getScanningResults();     } }

After that, you can check if the Location Services is ON, using LocationServices.SettingsApi and request the user to enable if this options is disabled. This is possible with Play Services LocationSettingsStatusCodes.RESOLUTION_REQUIRED callback.


I find related issue in AOSP issue tracker issue 185370 WifiManager#getScanResults() returns an empty array list if GPS is turned off.

The problem mentions from #1, The mobile must open location service to get wifi list of mobile.

And From #18, The Android project member claims that the development team has fixed the issue that you have reported and it will be available in a future build.

The APP is in targetSdkVersion 23, just follow above solution to check runtime permission. Enforcing to enable location services problem will fix in Android future release.


This won't work unless you have the GPS turned on. Weird, but it's the only way I got the list of wifi's :-(.