Stay organized with collections
Save and categorize content based on your preferences.
AudioManager.OnAudioFocusChangeListener
public
static
interface
AudioManager.OnAudioFocusChangeListener
android.media.AudioManager.OnAudioFocusChangeListener
|
Interface definition for a callback to be invoked when the audio focus of the system is
updated.
Summary
Public methods |
abstract
void
|
onAudioFocusChange(int focusChange)
Called on the listener to notify it the audio focus for this listener has been changed.
|
Public methods
onAudioFocusChange
public abstract void onAudioFocusChange (int focusChange)
Called on the listener to notify it the audio focus for this listener has been changed.
The focusChange value indicates whether the focus was gained,
whether the focus was lost, and whether that loss is transient, or whether the new focus
holder will hold it for an unknown amount of time.
When losing focus, listeners can use the focus change information to decide what
behavior to adopt when losing focus. A music player could for instance elect to lower
the volume of its music stream (duck) for transient focus losses, and pause otherwise.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# AudioManager.OnAudioFocusChangeListener\n\nAdded in [API level 8](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nAudioManager.OnAudioFocusChangeListener\n=======================================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/media/AudioManager.OnAudioFocusChangeListener \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\n\n\ninterface\nAudioManager.OnAudioFocusChangeListener\n`\n\n\n`\n\n\n`\n\n|-------------------------------------------------------|\n| android.media.AudioManager.OnAudioFocusChangeListener |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nInterface definition for a callback to be invoked when the audio focus of the system is\nupdated.\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onAudioFocusChange](/reference/android/media/AudioManager.OnAudioFocusChangeListener#onAudioFocusChange(int))`(int focusChange) ` Called on the listener to notify it the audio focus for this listener has been changed. |\n\nPublic methods\n--------------\n\n### onAudioFocusChange\n\nAdded in [API level 8](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onAudioFocusChange (int focusChange)\n```\n\nCalled on the listener to notify it the audio focus for this listener has been changed.\nThe focusChange value indicates whether the focus was gained,\nwhether the focus was lost, and whether that loss is transient, or whether the new focus\nholder will hold it for an unknown amount of time.\nWhen losing focus, listeners can use the focus change information to decide what\nbehavior to adopt when losing focus. A music player could for instance elect to lower\nthe volume of its music stream (duck) for transient focus losses, and pause otherwise.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `focusChange` | `int`: the type of focus change, one of [AudioManager.AUDIOFOCUS_GAIN](/reference/android/media/AudioManager#AUDIOFOCUS_GAIN), [AudioManager.AUDIOFOCUS_LOSS](/reference/android/media/AudioManager#AUDIOFOCUS_LOSS), [AudioManager.AUDIOFOCUS_LOSS_TRANSIENT](/reference/android/media/AudioManager#AUDIOFOCUS_LOSS_TRANSIENT) and [AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK](/reference/android/media/AudioManager#AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK). \u003cbr /\u003e |"]]