I need to scan all the available wifi networks but the method "wifiManager.startScan()" is deprecated and I don't find an alternative.
Does anyone know a real alternative?
I tried to look for more info in the developers Android portal however, it doesn't provide any alternative, or at least I couldn't find them.
I already checked:
I just need a list of the available networks and the information that we could get using "wifiManager.startScan()".
What do you recommend me?
Register a broadcast listener for SCAN_RESULTS_AVAILABLE_ACTION , which is called when scan requests are completed, providing their success/failure status. For devices running Android 10 (API level 29) and higher, this broadcast will be sent for any full Wi-Fi scan performed on the device by the platform or other apps.
Wi-Fi Manager (Wi-Fi) administers the wireless LAN settings and network profiles for a device, including the settings required for connecting to networks.
Description. WiFi Manager Lite allows you to manage wireless networks. The application gets you the ability to connect, view details about the wireless networks and set up networks. Moreover, you can manage multiple wireless network profiles.
It is marked deprecated with description: "The ability for apps to trigger scan requests will be removed in a future release." Currently this method works with some restrictions. In fact if you take a closer look at Wi-Fi scanning overview restrictions you can see that you can achieve your goal by meeting the conditions explained under Restrictions.
One more thing, if you are developing a system-privileged app or wondering how those apps get a wifi list even with location service turned off, they use android.Manifest.permission.NETWORK_SETUP_WIZARD
or android.Manifest.permission.NETWORK_SETTINGS
which are system|signature level permissions. Read WifiPermissionsUtil.java:
/**
* API to determine if the caller has permissions to get scan results. Throws SecurityException
* if the caller has no permission.
* @param pkgName package name of the application requesting access
* @param uid The uid of the package
*/
public void enforceCanAccessScanResults(String pkgName, int uid) throws SecurityException {
mAppOps.checkPackage(uid, pkgName);
// Apps with NETWORK_SETTINGS & NETWORK_SETUP_WIZARD are granted a bypass.
if (checkNetworkSettingsPermission(uid) || checkNetworkSetupWizardPermission(uid)) {
return;
}
// Location mode must be enabled
if (!isLocationModeEnabled()) {
// Location mode is disabled, scan results cannot be returned
throw new SecurityException("Location mode is disabled for the device");
}
// Check if the calling Uid has CAN_READ_PEER_MAC_ADDRESS permission.
boolean canCallingUidAccessLocation = checkCallerHasPeersMacAddressPermission(uid);
// LocationAccess by App: caller must have
// Coarse Location permission to have access to location information.
boolean canAppPackageUseLocation = checkCallersLocationPermission(pkgName, uid);
// If neither caller or app has location access, there is no need to check
// any other permissions. Deny access to scan results.
if (!canCallingUidAccessLocation && !canAppPackageUseLocation) {
throw new SecurityException("UID " + uid + " has no location permission");
}
// Check if Wifi Scan request is an operation allowed for this App.
if (!isScanAllowedbyApps(pkgName, uid)) {
throw new SecurityException("UID " + uid + " has no wifi scan permission");
}
// If the User or profile is current, permission is granted
// Otherwise, uid must have INTERACT_ACROSS_USERS_FULL permission.
if (!isCurrentProfile(uid) && !checkInteractAcrossUsersFull(uid)) {
throw new SecurityException("UID " + uid + " profile not permitted");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With