android - WifiManager startScan 已弃用。选择?
问题描述
我需要扫描所有可用的 wifi 网络,但“wifiManager.startScan()”方法已被弃用,我找不到替代方法。
有人知道真正的替代方案吗?
我试图在开发人员 Android 门户中查找更多信息,但是它没有提供任何替代方案,或者至少我找不到它们。
我已经检查过:
- 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()”获得的信息。
你给我推荐什么?
解决方案
它被标记为已弃用,并带有描述:“应用程序触发扫描请求的能力将在未来的版本中删除。” 目前这种方法有一些限制。事实上,如果您仔细查看Wi-Fi 扫描概述限制,您会发现您可以通过满足限制中 说明的条件来实现您的目标。
还有一件事,如果您正在开发系统特权应用程序,或者想知道即使关闭位置服务,这些应用程序如何获得 wifi 列表,它们使用android.Manifest.permission.NETWORK_SETUP_WIZARD
或android.Manifest.permission.NETWORK_SETTINGS
哪些是系统|签名级别权限。阅读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");
}
}
推荐阅读
- python - 将嵌套字典转换为数据框,键作为行名,值中的字典作为列?
- command-line-interface - 使用 spaCy 命令行训练器管理训练/开发拆分
- arrays - 二维数组中的数组大小不匹配
- sql - PostgreSQL INSERT INTO 表不存在
- python - 关于python导入、函数、子目录的一个非常简单的问题
- java - SharedPreferences:为什么我的值没有被覆盖?
- graphql - 使用 request-promise 将数据发布到 graphql 服务器
- python - 重新采样 Python 熊猫排除某些字段
- excel - vba中的Instr不使用公式单元格
- php - 随着时间的推移,慢慢地用 Vue 替换 Laravel 刀片文件,但它变得混乱