在 Android 上获取 Wifi 扫描位置系统设置,不推荐使用功能

问题描述 投票:0回答:1

我需要确定位置设置中的 Wifi 扫描设置是打开还是关闭。这两种方法似乎都已被弃用。

以下两种方法似乎可以在提出问题时获得所需的值:

WifiManager.isScanAlwaysAvailable

Settings.Global.getInt(
            contentResolver,
            "wifi_scan_always_enabled"
        )

但是它们都在 API 中被标记为已弃用,设置明确要求我使用

WifiManager.isScanAlwaysAvailable
:

        /**
        * Setting to allow scans to be enabled even wifi is turned off for connectivity.
        * @hide
        * @deprecated To be removed. Use {@link WifiManager#setScanAlwaysAvailable(boolean)} for
        * setting the value and {@link WifiManager#isScanAlwaysAvailable()} for query.
        */
        @Deprecated
        @Readable
        public static final String WIFI_SCAN_ALWAYS_AVAILABLE =
                "wifi_scan_always_enabled";

在 WifiManager 中:

    /**
     * Check if scanning is always available.
     *
     * If this return {@code true}, apps can issue {@link #startScan} and fetch scan results
     * even when Wi-Fi is turned off.
     *
     * To change this setting, see {@link #ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE}.
     * @deprecated The ability for apps to trigger scan requests will be removed in a future
     * release.
     */
    @Deprecated
    public boolean isScanAlwaysAvailable() {

有没有更新、更稳定的方法来做到这一点?

android wifi wifimanager android-settings
1个回答
0
投票

尝试以下代码来检索 WIFI 管理器:

Android.Net.Wifi.WifiManager WifiManager = (Android.Net.Wifi.WifiManager)GetSystemService(Android.Content.Context.WifiService);

希望这有帮助

© www.soinside.com 2019 - 2024. All rights reserved.