IT. Expert System.

Android Reference

WifiManager


android.net.wifi

Class WifiManager



  • public class WifiManager
    extends Object
    This class provides the primary API for managing all aspects of Wi-Fi connectivity. Get an instance of this class by calling Context.getSystemService(Context.WIFI_SERVICE). It deals with several categories of items:
    • The list of configured networks. The list can be viewed and updated, and attributes of individual entries can be modified.
    • The currently active Wi-Fi network, if any. Connectivity can be established or torn down, and dynamic information about the state of the network can be queried.
    • Results of access point scans, containing enough information to make decisions about what access point to connect to.
    • It defines the names of various Intent actions that are broadcast upon any sort of change in Wi-Fi state.
    This is the API to use when performing Wi-Fi specific operations. To perform operations that pertain to network connectivity at an abstract level, use ConnectivityManager.
    • Constructor Detail

      • WifiManager

        public WifiManager(Context context,
                   IWifiManager service)
        Create a new WifiManager instance. Applications will almost always want to use Context.getSystemService() to retrieve the standard Context.WIFI_SERVICE.
        Parameters:
        context - the application context
        service - the Binder interface
    • Method Detail

      • getConfiguredNetworks

        public List<WifiConfiguration> getConfiguredNetworks()
        Return a list of all the networks configured in the supplicant. Not all fields of WifiConfiguration are returned. Only the following fields are filled in:
        • networkId
        • SSID
        • BSSID
        • priority
        • allowedProtocols
        • allowedKeyManagement
        • allowedAuthAlgorithms
        • allowedPairwiseCiphers
        • allowedGroupCiphers
        Returns:
        a list of network configurations in the form of a list of WifiConfiguration objects. Upon failure to fetch or when when Wi-Fi is turned off, it can be null.
      • addNetwork

        public int addNetwork(WifiConfiguration config)
        Add a new network description to the set of configured networks. The networkId field of the supplied configuration object is ignored.

        The new network will be marked DISABLED by default. To enable it, called enableNetwork(int, boolean).

        Parameters:
        config - the set of variables that describe the configuration, contained in a WifiConfiguration object.
        Returns:
        the ID of the newly created network description. This is used in other operations to specified the network to be acted upon. Returns -1 on failure.
      • updateNetwork

        public int updateNetwork(WifiConfiguration config)
        Update the network description of an existing configured network.
        Parameters:
        config - the set of variables that describe the configuration, contained in a WifiConfiguration object. It may be sparse, so that only the items that are being changed are non-null. The networkId field must be set to the ID of the existing network being updated.
        Returns:
        Returns the networkId of the supplied WifiConfiguration on success.
        Returns -1 on failure, including when the networkId field of the WifiConfiguration does not refer to an existing network.
      • removeNetwork

        public boolean removeNetwork(int netId)
        Remove the specified network from the list of configured networks. This may result in the asynchronous delivery of state change events.
        Parameters:
        netId - the integer that identifies the network configuration to the supplicant
        Returns:
        true if the operation succeeded
      • enableNetwork

        public boolean enableNetwork(int netId,
                            boolean disableOthers)
        Allow a previously configured network to be associated with. If disableOthers is true, then all other configured networks are disabled, and an attempt to connect to the selected network is initiated. This may result in the asynchronous delivery of state change events.
        Parameters:
        netId - the ID of the network in the list of configured networks
        disableOthers - if true, disable all other networks. The way to select a particular network to connect to is specify true for this parameter.
        Returns:
        true if the operation succeeded
      • disableNetwork

        public boolean disableNetwork(int netId)
        Disable a configured network. The specified network will not be a candidate for associating. This may result in the asynchronous delivery of state change events.
        Parameters:
        netId - the ID of the network as returned by addNetwork(android.net.wifi.WifiConfiguration).
        Returns:
        true if the operation succeeded
      • disconnect

        public boolean disconnect()
        Disassociate from the currently active access point. This may result in the asynchronous delivery of state change events.
        Returns:
        true if the operation succeeded
      • reconnect

        public boolean reconnect()
        Reconnect to the currently active access point, if we are currently disconnected. This may result in the asynchronous delivery of state change events.
        Returns:
        true if the operation succeeded
      • reassociate

        public boolean reassociate()
        Reconnect to the currently active access point, even if we are already connected. This may result in the asynchronous delivery of state change events.
        Returns:
        true if the operation succeeded
      • pingSupplicant

        public boolean pingSupplicant()
        Check that the supplicant daemon is responding to requests.
        Returns:
        true if we were able to communicate with the supplicant and it returned the expected response to the PING message.
      • startScan

        public boolean startScan()
        Request a scan for access points. Returns immediately. The availability of the results is made known later by means of an asynchronous event sent on completion of the scan.
        Returns:
        true if the operation succeeded, i.e., the scan was initiated
      • startScanActive

        public boolean startScanActive()
        Request a scan for access points. Returns immediately. The availability of the results is made known later by means of an asynchronous event sent on completion of the scan. This is a variant of startScan that forces an active scan, even if passive scans are the current default
        Returns:
        true if the operation succeeded, i.e., the scan was initiated
      • getConnectionInfo

        public WifiInfo getConnectionInfo()
        Return dynamic information about the current Wi-Fi connection, if any is active.
        Returns:
        the Wi-Fi information, contained in WifiInfo.
      • getScanResults

        public List<ScanResult> getScanResults()
        Return the results of the latest access point scan.
        Returns:
        the list of access points found in the most recent scan.
      • saveConfiguration

        public boolean saveConfiguration()
        Tell the supplicant to persist the current list of configured networks.

        Note: It is possible for this method to change the network IDs of existing networks. You should assume the network IDs can be different after calling this method.

        Returns:
        true if the operation succeeded
      • setCountryCode

        public void setCountryCode(String country,
                          boolean persist)
        Set the country code.
        Parameters:
        countryCode - country code in ISO 3166 format.
        persist - true if this needs to be remembered
      • isDualBandSupported

        public boolean isDualBandSupported()
        Check if the chipset supports dual frequency band (2.4 GHz and 5 GHz)
        Returns:
        true if supported, false otherwise.
      • getDhcpInfo

        public DhcpInfo getDhcpInfo()
        Return the DHCP-assigned addresses from the last successful DHCP request, if any.
        Returns:
        the DHCP information
      • setWifiEnabled

        public boolean setWifiEnabled(boolean enabled)
        Enable or disable Wi-Fi.
        Parameters:
        enabled - true to enable, false to disable.
        Returns:
        true if the operation succeeds (or if the existing state is the same as the requested state).
      • isWifiEnabled

        public boolean isWifiEnabled()
        Return whether Wi-Fi is enabled or disabled.
        Returns:
        true if Wi-Fi is enabled
        See Also:
        getWifiState()
      • getTxPacketCount

        public void getTxPacketCount(WifiManager.TxPacketCountListener listener)
        Return TX packet counter, for CTS test of WiFi watchdog.
        Parameters:
        listener - is the interface to receive result
      • calculateSignalLevel

        public static int calculateSignalLevel(int rssi,
                               int numLevels)
        Calculates the level of the signal. This should be used any time a signal is being shown.
        Parameters:
        rssi - The power of the signal measured in RSSI.
        numLevels - The number of levels to consider in the calculated level.
        Returns:
        A level of the signal, given in the range of 0 to numLevels-1 (both inclusive).
      • compareSignalLevel

        public static int compareSignalLevel(int rssiA,
                             int rssiB)
        Compares two signal strengths.
        Parameters:
        rssiA - The power of the first signal measured in RSSI.
        rssiB - The power of the second signal measured in RSSI.
        Returns:
        Returns <0 if the first signal is weaker than the second signal, 0 if the two signals have the same strength, and >0 if the first signal is stronger than the second signal.
      • setWifiApEnabled

        public boolean setWifiApEnabled(WifiConfiguration wifiConfig,
                               boolean enabled)
        Start AccessPoint mode with the specified configuration. If the radio is already running in AP mode, update the new configuration Note that starting in access point mode disables station mode operation
        Parameters:
        wifiConfig - SSID, security and channel details as part of WifiConfiguration
        Returns:
        true if the operation succeeds, false otherwise
      • isWifiApEnabled

        public boolean isWifiApEnabled()
        Return whether Wi-Fi AP is enabled or disabled.
        Returns:
        true if Wi-Fi AP is enabled
        See Also:
        getWifiApState()
      • getWifiApConfiguration

        public WifiConfiguration getWifiApConfiguration()
        Gets the Wi-Fi AP Configuration.
        Returns:
        AP details in WifiConfiguration
      • setWifiApConfiguration

        public boolean setWifiApConfiguration(WifiConfiguration wifiConfig)
        Sets the Wi-Fi AP Configuration.
        Returns:
        true if the operation succeeded, false otherwise
      • startWifi

        public boolean startWifi()
        Start the driver and connect to network. This function will over-ride WifiLock and device idle status. For example, even if the device is idle or there is only a scan-only lock held, a start wifi would mean that wifi connection is kept active until a stopWifi() is sent. This API is used by WifiStateTracker
        Returns:
        true if the operation succeeds else false
      • stopWifi

        public boolean stopWifi()
        Disconnect from a network (if any) and stop the driver. This function will over-ride WifiLock and device idle status. Wi-Fi stays inactive until a startWifi() is issued. This API is used by WifiStateTracker
        Returns:
        true if the operation succeeds else false
      • addToBlacklist

        public boolean addToBlacklist(String bssid)
        Add a bssid to the supplicant blacklist This API is used by WifiWatchdogService
        Returns:
        true if the operation succeeds else false
      • clearBlacklist

        public boolean clearBlacklist()
        Clear the supplicant blacklist This API is used by WifiWatchdogService
        Returns:
        true if the operation succeeds else false
      • connect

        public void connect(WifiConfiguration config,
                   WifiManager.ActionListener listener)
        Connect to a network with the given configuration. The network also gets added to the supplicant configuration. For a new network, this function is used instead of a sequence of addNetwork(), enableNetwork(), saveConfiguration() and reconnect()
        Parameters:
        config - the set of variables that describe the configuration, contained in a WifiConfiguration object.
        listener - for callbacks on success or failure. Can be null.
        Throws:
        IllegalStateException - if the WifiManager instance needs to be initialized again
      • connect

        public void connect(int networkId,
                   WifiManager.ActionListener listener)
        Connect to a network with the given networkId. This function is used instead of a enableNetwork(), saveConfiguration() and reconnect()
        Parameters:
        networkId - the network id identifiying the network in the supplicant configuration list
        listener - for callbacks on success or failure. Can be null.
        Throws:
        IllegalStateException - if the WifiManager instance needs to be initialized again
      • save

        public void save(WifiConfiguration config,
                WifiManager.ActionListener listener)
        Save the given network in the supplicant config. If the network already exists, the configuration is updated. A new network is enabled by default. For a new network, this function is used instead of a sequence of addNetwork(), enableNetwork() and saveConfiguration(). For an existing network, it accomplishes the task of updateNetwork() and saveConfiguration()
        Parameters:
        config - the set of variables that describe the configuration, contained in a WifiConfiguration object.
        listener - for callbacks on success or failure. Can be null.
        Throws:
        IllegalStateException - if the WifiManager instance needs to be initialized again
      • forget

        public void forget(int netId,
                  WifiManager.ActionListener listener)
        Delete the network in the supplicant config. This function is used instead of a sequence of removeNetwork() and saveConfiguration().
        Parameters:
        config - the set of variables that describe the configuration, contained in a WifiConfiguration object.
        listener - for callbacks on success or failure. Can be null.
        Throws:
        IllegalStateException - if the WifiManager instance needs to be initialized again
      • disable

        public void disable(int netId,
                   WifiManager.ActionListener listener)
        Disable network
        Parameters:
        netId - is the network Id
        listener - for callbacks on success or failure. Can be null.
        Throws:
        IllegalStateException - if the WifiManager instance needs to be initialized again
      • startWps

        public void startWps(WpsInfo config,
                    WifiManager.WpsListener listener)
        Start Wi-fi Protected Setup
        Parameters:
        config - WPS configuration
        listener - for callbacks on success or failure. Can be null.
        Throws:
        IllegalStateException - if the WifiManager instance needs to be initialized again
      • cancelWps

        public void cancelWps(WifiManager.ActionListener listener)
        Cancel any ongoing Wi-fi Protected Setup
        Parameters:
        listener - for callbacks on success or failure. Can be null.
        Throws:
        IllegalStateException - if the WifiManager instance needs to be initialized again
      • getWifiServiceMessenger

        public Messenger getWifiServiceMessenger()
        Get a reference to WifiService handler. This is used by a client to establish an AsyncChannel communication with WifiService
        Returns:
        Messenger pointing to the WifiService handler
      • getWifiStateMachineMessenger

        public Messenger getWifiStateMachineMessenger()
        Get a reference to WifiStateMachine handler.
        Returns:
        Messenger pointing to the WifiService handler
      • getConfigFile

        public String getConfigFile()
        Returns the file in which IP and proxy configuration data is stored
      • createWifiLock

        public WifiManager.WifiLock createWifiLock(int lockType,
                                          String tag)
        Creates a new WifiLock.
        Parameters:
        lockType - the type of lock to create. See WIFI_MODE_FULL, WIFI_MODE_FULL_HIGH_PERF and WIFI_MODE_SCAN_ONLY for descriptions of the types of Wi-Fi locks.
        tag - a tag for the WifiLock to identify it in debugging messages. This string is never shown to the user under normal conditions, but should be descriptive enough to identify your application and the specific WifiLock within it, if it holds multiple WifiLocks.
        Returns:
        a new, unacquired WifiLock with the given tag.
        See Also:
        WifiManager.WifiLock
      • createWifiLock

        public WifiManager.WifiLock createWifiLock(String tag)
        Creates a new WifiLock.
        Parameters:
        tag - a tag for the WifiLock to identify it in debugging messages. This string is never shown to the user under normal conditions, but should be descriptive enough to identify your application and the specific WifiLock within it, if it holds multiple WifiLocks.
        Returns:
        a new, unacquired WifiLock with the given tag.
        See Also:
        WifiManager.WifiLock
      • createMulticastLock

        public WifiManager.MulticastLock createMulticastLock(String tag)
        Create a new MulticastLock
        Parameters:
        tag - a tag for the MulticastLock to identify it in debugging messages. This string is never shown to the user under normal conditions, but should be descriptive enough to identify your application and the specific MulticastLock within it, if it holds multiple MulticastLocks.
        Returns:
        a new, unacquired MulticastLock with the given tag.
        See Also:
        WifiManager.MulticastLock
      • isMulticastEnabled

        public boolean isMulticastEnabled()
        Check multicast filter status.
        Returns:
        true if multicast packets are allowed.
      • initializeMulticastFiltering

        public boolean initializeMulticastFiltering()
        Initialize the multicast filtering to 'on'
      • captivePortalCheckComplete

        public void captivePortalCheckComplete()
      • finalize

        protected void finalize()
                         throws Throwable
        Description copied from class: Object
        Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

        Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

        If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

        Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

        Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

        Overrides:
        finalize in class Object
        Throws:
        Throwable


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 415 / 158733953. Delta: 0.08339 с