snoozebaumer
snoozebaumer

Reputation: 1

Fetching Wifi-Scanning location system setting on Android without deprecated functions

I need to figure out whether the Wifi-Scanning setting is turned on or turned off in the location settings. Both ways to do this seem to be deprecated.

The following two ways seem to get the desired value as of asking the question:

WifiManager.isScanAlwaysAvailable

and

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

but they're both marked as deprecated in the API, with Settings explicitly requesting I use 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";

and in 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() {

Is there a newer, more stable way to do this?

Upvotes: 0

Views: 183

Answers (0)

Related Questions