我需要确定位置设置中的 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() {
有没有更新、更稳定的方法来做到这一点?
尝试以下代码来检索 WIFI 管理器:
Android.Net.Wifi.WifiManager WifiManager = (Android.Net.Wifi.WifiManager)GetSystemService(Android.Content.Context.WifiService);
希望这有帮助