HeadphoneFence
Stay organized with collections
Save and categorize content based on your preferences.
Use this class to create headphone state fences.
Note: Values that indicate a changing state are momentarily TRUE
for about 5 seconds, then automatically revert to FALSE
.
Please be sure to follow the guidelines in the Awareness API Guide
.
Public Method Summary
static AwarenessFence
|
during
(int headphoneState) This fence is in the TRUE
state when the headphones are in the specified state.
|
static AwarenessFence
|
pluggingIn
() This fence is momentarily (about 5 seconds) in the TRUE
state when headphones are plugged in to the device.
|
static AwarenessFence
|
unplugging
() This fence is momentarily (about 5 seconds) in the TRUE
state when headphones are unplugged from the device.
|
Inherited Method Summary
From class java.lang.Object
Public Methods
public static AwarenessFence
during
(int
headphoneState)
This fence is in the TRUE
state when the headphones are in the specified state.
This fence is momentarily (about 5 seconds) in the TRUE
state when headphones are plugged in to the device.
This fence is momentarily (about 5 seconds) in the TRUE
state when headphones are unplugged from the device.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eHeadphoneFence\u003c/code\u003e class is used to create fences that react to headphone state changes on an Android device.\u003c/p\u003e\n"],["\u003cp\u003eThree static methods, \u003ccode\u003eduring()\u003c/code\u003e, \u003ccode\u003epluggingIn()\u003c/code\u003e, and \u003ccode\u003eunplugging()\u003c/code\u003e, are provided to create fences for specific headphone states or events.\u003c/p\u003e\n"],["\u003cp\u003eFences indicating a change in headphone state (\u003ccode\u003epluggingIn()\u003c/code\u003e and \u003ccode\u003eunplugging()\u003c/code\u003e) are only TRUE for approximately 5 seconds.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should consult the Awareness API Guide for further implementation details and best practices.\u003c/p\u003e\n"]]],["The `HeadphoneFence` class creates fences for headphone states. It offers three static methods: `during`, `pluggingIn`, and `unplugging`. `during` checks if headphones are in a specified state (plugged in or unplugged). `pluggingIn` and `unplugging` detect when headphones are respectively connected or disconnected, momentarily setting the fence to TRUE for approximately five seconds.\n"],null,["# HeadphoneFence\n\npublic final class **HeadphoneFence** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nUse this class to create headphone state fences.\n\nNote: Values that indicate a changing state are momentarily [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nfor about 5 seconds, then automatically revert to [FALSE](/android/reference/com/google/android/gms/awareness/fence/FenceState#FALSE).\n\nPlease be sure to follow the guidelines in the [Awareness API Guide](//developers.google.com/awareness) . \n\n### Public Method Summary\n\n|---------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) | [during](/android/reference/com/google/android/gms/awareness/fence/HeadphoneFence#during(int))(int headphoneState) This fence is in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE) state when the headphones are in the specified state. |\n| static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) | [pluggingIn](/android/reference/com/google/android/gms/awareness/fence/HeadphoneFence#pluggingIn())() This fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE) state when headphones are plugged in to the device. |\n| static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) | [unplugging](/android/reference/com/google/android/gms/awareness/fence/HeadphoneFence#unplugging())() This fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE) state when headphones are unplugged from the device. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence)\n**during** (int headphoneState)\n\nThis fence is in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nstate when the headphones are in the specified state. \n\n##### Parameters\n\n| headphoneState | Valid values are [PLUGGED_IN](/android/reference/com/google/android/gms/awareness/state/HeadphoneState#PLUGGED_IN) or [UNPLUGGED](/android/reference/com/google/android/gms/awareness/state/HeadphoneState#UNPLUGGED) |\n|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) \n\n#### public static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence)\n**pluggingIn** ()\n\nThis fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nstate when headphones are plugged in to the device. \n\n##### Returns\n\n- [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence) \n\n#### public static [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence)\n**unplugging** ()\n\nThis fence is momentarily (about 5 seconds) in the [TRUE](/android/reference/com/google/android/gms/awareness/fence/FenceState#TRUE)\nstate when headphones are unplugged from the device. \n\n##### Returns\n\n- [AwarenessFence](/android/reference/com/google/android/gms/awareness/fence/AwarenessFence)"]]