WifiManager startScan已弃用。另类? [英] WifiManager startScan deprecated. Alternative?
问题描述
我需要扫描所有可用的wifi网络,但是不建议使用 wifiManager.startScan()方法,并且找不到替代方法。
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?
我试图在开发人员Android门户中查找更多信息,但是它没有提供任何替代方法,或者至少我找不到
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.
我已经检查过:
- https://developer.android.com/reference/android/net/wifi/ WifiManager.html#startScan%28%29
- https://developer.android.com/guide/topics/connectivity/wifi-scan#java
- https://developer.android.com/reference/android/net/wifi/WifiManager.html#startScan%28%29
- https://developer.android.com/guide/topics/connectivity/wifi-scan#java
我只需要一个可用网络列表,以及我们可以使用 wifiManager.startScan()获得的信息。
I just need a list of the available networks and the information that we could get using "wifiManager.startScan()".
您怎么建议
推荐答案
已被标记为不推荐使用,其描述为:以后将取消应用程序触发扫描请求的功能发布。
当前,此方法有一些限制。实际上,如果您仔细查看 Wi-Fi扫描概述限制
,您可以看到满足限制中所述的条件,可以实现自己的目标。
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.
还有一件事,如果您正在开发系统特权的应用程序,或者想知道即使关闭了位置服务,这些应用程序如何获得wifi列表,它们也会使用 android.Manifest.permission.NETWORK_SETUP_WIZARD
或 android.Manifest.permission.NETWORK_SETTINGS
是系统|签名级别的权限。阅读 WifiPermissionsUtil.java :
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");
}
}
这篇关于WifiManager startScan已弃用。另类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!