【问题标题】:WifiManager startScan deprecated. Alternative?WifiManager startScan 已弃用。选择?
【发布时间】:2019-05-31 19:57:46
【问题描述】:

我需要扫描所有可用的 wifi 网络,但“wifiManager.startScan()”方法已被弃用,我找不到替代方法。

有人知道真正的替代品吗?

我试图在开发者 Android 门户中查找更多信息,但是它没有提供任何替代方案,或者至少我找不到它们。

我已经检查过了:

我只需要一个可用网络列表以及我们可以使用“wifiManager.startScan()”获取的信息。

你有什么推荐给我的?

【问题讨论】:

  • 不知道你有没有看过我的回答。不推荐使用的方法并不一定意味着它不起作用。如果您对作业的实施仍有问题,请分享您的代码。

标签: android deprecated wifimanager


【解决方案1】:

它被标记为已弃用,并带有说明:“应用程序触发扫描请求的功能将在未来版本中删除。” 目前这种方法有一些限制。事实上,如果你仔细看看Wi-Fi scanning overview restrictions 您可以看到满足限制中说明的条件即可实现目标。

还有一件事,如果您正在开发一个系统特权应用程序,或者想知道这些应用程序如何在关闭位置服务的情况下获得 wifi 列表,它们会使用android.Manifest.permission.NETWORK_SETUP_WIZARDandroid.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");
        }
    } 

【讨论】:

    猜你喜欢
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 2014-06-13
    • 2020-09-04
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多