Added in API level 4

MulticastLock


open class MulticastLock
kotlin.Any
   ↳ android.net.wifi.WifiManager.MulticastLock

Allows an application to receive Wifi Multicast packets. Normally the Wifi stack filters out packets not explicitly addressed to this device. Acquring a MulticastLock will cause the stack to receive packets addressed to multicast addresses. Processing these extra packets can cause a noticeable battery drain and should be disabled when not needed.

Summary

Public methods
open Unit

Locks Wifi Multicast on until release is called.

open Boolean

Checks whether this MulticastLock is currently held.

open Unit

Unlocks Wifi Multicast, restoring the filter of packets not addressed specifically to this device and saving power.

open Unit

Controls whether this is a reference-counted or non-reference- counted MulticastLock.

open String

Protected methods
open Unit

Public methods

acquire

Added in API level 4
open fun acquire(): Unit

Locks Wifi Multicast on until release is called. If this MulticastLock is reference-counted each call to acquire will increment the reference count, and the wifi interface will receive multicast packets as long as the reference count is above zero. If this MulticastLock is not reference-counted, the first call to acquire will turn on the multicast packets, but subsequent calls will be ignored. Only one call to release will be required, regardless of the number of times that acquire is called. Note that other applications may also lock Wifi Multicast on. Only they can relinquish their lock. Also note that applications cannot leave Multicast locked on. When an app exits or crashes, any Multicast locks will be released.

isHeld

Added in API level 4
open fun isHeld(): Boolean

Checks whether this MulticastLock is currently held.

Return
Boolean true if this MulticastLock is held, false otherwise

release

Added in API level 4
open fun release(): Unit

Unlocks Wifi Multicast, restoring the filter of packets not addressed specifically to this device and saving power. If this MulticastLock is reference-counted, each call to release will decrement the reference count, and the multicast packets will only stop being received when the reference count reaches zero. If the reference count goes below zero (that is, if release is called a greater number of times than acquire), an exception is thrown. If this MulticastLock is not reference-counted, the first call to release (after the radio was multicast locked using acquire) will unlock the multicast, and subsequent calls will be ignored. Note that if any other Wifi Multicast Locks are still outstanding this release call will not have an immediate effect. Only when all applications have released all their Multicast Locks will the Multicast filter be turned back on. Also note that when an app exits or crashes all of its Multicast Locks will be automatically released.

setReferenceCounted

Added in API level 4
open fun setReferenceCounted(refCounted: Boolean): Unit

Controls whether this is a reference-counted or non-reference- counted MulticastLock. Reference-counted MulticastLocks keep track of the number of calls to acquire and release, and only stop the reception of multicast packets when every call to acquire has been balanced with a call to release. Non-reference- counted MulticastLocks allow the reception of multicast packets whenever acquire is called and stop accepting multicast packets whenever release is called.

Parameters
refCounted Boolean: true if this MulticastLock should keep a reference count

toString

Added in API level 4
open fun toString(): String
Return
String a string representation of the object.

Protected methods

finalize

Added in API level 4
protected open fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method