On Android 8.0, not getting wifi list using wifiManager, below API level 26 I am getting the list.
This function returns the WifiManager
Object
public static WifiManager getWifiManager(Context context) {
WifiManager wifiManager = null;
try {
wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
} catch (NullPointerException e) {
e.printStackTrace();
}
return wifiManager;
}
This function returns the wifi list
public static List<ScanResult> getWifiScanResults(Boolean sorted, Context context) {
WifiManager wifiManager = NetworkUtil.getWifiManager(context);
List<ScanResult> wifiList = wifiManager.getScanResults();
//Remove results with empty ssid
List<ScanResult> wifiListNew = new ArrayList<>();
for (ScanResult scanResult : wifiList) {
if (!scanResult.SSID.equals(""))
wifiListNew.add(scanResult);
}
wifiList.clear();
wifiList.addAll(wifiListNew);
return wifiList;
}
I had registered the BroadcastReceiver
WiFiMainActivity.this.registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
and here is the startScan() Method
public static void startScan(Context context) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
}
User having following permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Not able to track the bug on android 8.0 Oreo, is there any other permission that I am missing.