Scanning for wifi signals only in 2.4Ghz band

后端 未结 4 561
南方客
南方客 2021-02-09 11:56

I need to scan for available Wi-Fi signals and their strengths. I\'m using wifiManager.startScan(); and asynchronous wifiManager.getScanResult();.

4条回答
  •  时光说笑
    2021-02-09 12:26

    NOTE: These api's are removed from Android Nogut version. Applicable till Mashmallow

    /**
     * Auto settings in the driver. The driver could choose to operate on both
     * 2.4 GHz and 5 GHz or make a dynamic decision on selecting the band.
     * @hide
     */
    public static final int WIFI_FREQUENCY_BAND_AUTO = 0;
    
    /**
     * Operation on 5 GHz alone
     * @hide
     */
    public static final int WIFI_FREQUENCY_BAND_5GHZ = 1;
    
    /**
     * Operation on 2.4 GHz alone
     * @hide
     */
    public static final int WIFI_FREQUENCY_BAND_2GHZ = 2;
    

    Use above constants part of WifiManager.java, to set the required frequency bands. And we can set frequency with API setFrequencyBand(int mode, boolean persist). These are hidden API's.

    code snippet:

    WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
    
    // To scan only 2.4 GHz Frequency band
    
    // true, if this needs to be remembered
    
    wm.setFrequencyBand(2, false);
    
    // Start scan.
    
    wm.startScan();
    
    // To get the frequency band used.
    
    int band = wm.getFrequncyBand();
    

提交回复
热议问题