CarAppFocusManager
public
final
class
CarAppFocusManager
extends Object
java.lang.Object | |
↳ | android.car.CarAppFocusManager |
CarAppFocusManager allows applications to set and listen for the current application focus like active navigation or active voice command. Usually only one instance of such application should run in the system, and other app setting the flag for the matching app should lead into other app to stop.
Summary
Nested classes | |
---|---|
interface |
CarAppFocusManager.OnAppFocusChangedListener
Listener to get notification for app getting information on application type status changes. |
interface |
CarAppFocusManager.OnAppFocusOwnershipCallback
Listener to get notification for app getting information on app type ownership loss. |
Constants | |
---|---|
int |
APP_FOCUS_REQUEST_FAILED
A failed focus change request. |
int |
APP_FOCUS_REQUEST_SUCCEEDED
A successful focus change request. |
int |
APP_FOCUS_TYPE_NAVIGATION
Represents navigation focus. |
int |
APP_FOCUS_TYPE_VOICE_COMMAND
This constant was deprecated
in API level 29.
use |
Public methods | |
---|---|
void
|
abandonAppFocus(CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback)
Abandons all focuses, marking them as inactive. |
void
|
abandonAppFocus(CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback, int appType)
Abandons the given focus, marking it as inactive. |
void
|
addFocusListener(CarAppFocusManager.OnAppFocusChangedListener listener, int appType)
Register listener to monitor app focus change. |
boolean
|
isOwningFocus(CarAppFocusManager.OnAppFocusOwnershipCallback callback, int appType)
Checks if listener is associated with active a focus |
void
|
removeFocusListener(CarAppFocusManager.OnAppFocusChangedListener listener, int appType)
Unregister listener for application type and stop listening focus change events. |
void
|
removeFocusListener(CarAppFocusManager.OnAppFocusChangedListener listener)
Unregister listener and stop listening focus change events. |
int
|
requestAppFocus(int appType, CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback)
Requests application focus. |
Inherited methods | |
---|---|
Constants
APP_FOCUS_REQUEST_FAILED
public static final int APP_FOCUS_REQUEST_FAILED
A failed focus change request.
Constant Value: 0 (0x00000000)
APP_FOCUS_REQUEST_SUCCEEDED
public static final int APP_FOCUS_REQUEST_SUCCEEDED
A successful focus change request.
Constant Value: 1 (0x00000001)
APP_FOCUS_TYPE_NAVIGATION
public static final int APP_FOCUS_TYPE_NAVIGATION
Represents navigation focus.
Constant Value: 1 (0x00000001)
APP_FOCUS_TYPE_VOICE_COMMAND
public static final int APP_FOCUS_TYPE_VOICE_COMMAND
This constant was deprecated
in API level 29.
use VoiceInteractionService
instead.
Represents voice command focus.
Constant Value: 2 (0x00000002)
Public methods
abandonAppFocus
public void abandonAppFocus (CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback)
Abandons all focuses, marking them as inactive. This also involves releasing ownership for the focus.
abandonAppFocus
public void abandonAppFocus (CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback, int appType)
Abandons the given focus, marking it as inactive. This also involves releasing ownership for the focus.
Parameters | |
---|---|
appType |
int : Value is APP_FOCUS_TYPE_NAVIGATION |
addFocusListener
public void addFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener, int appType)
Register listener to monitor app focus change.
Parameters | |
---|---|
appType |
int : Application type to get notification for.
Value is APP_FOCUS_TYPE_NAVIGATION |
isOwningFocus
public boolean isOwningFocus (CarAppFocusManager.OnAppFocusOwnershipCallback callback, int appType)
Checks if listener is associated with active a focus
Parameters | |
---|---|
appType |
int : Value is APP_FOCUS_TYPE_NAVIGATION |
Returns | |
---|---|
boolean |
removeFocusListener
public void removeFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener, int appType)
Unregister listener for application type and stop listening focus change events.
Parameters | |
---|---|
appType |
int : Value is APP_FOCUS_TYPE_NAVIGATION |
removeFocusListener
public void removeFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener)
Unregister listener and stop listening focus change events.
requestAppFocus
public int requestAppFocus (int appType, CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback)
Requests application focus.
By requesting this, the application is becoming owner of the focus, and will get
OnAppFocusOwnershipCallback#onAppFocusOwnershipLost(int)
if ownership is given to other app by calling this. Fore-ground app will have higher priority
and other app cannot set the same focus while owner is in fore-ground.
Returns | |
---|---|
int |
APP_FOCUS_REQUEST_FAILED or APP_FOCUS_REQUEST_SUCCEEDED
Value is APP_FOCUS_REQUEST_FAILED , or APP_FOCUS_REQUEST_SUCCEEDED |
Throws | |
---|---|
SecurityException |
If owner cannot be changed. |
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 2024-04-11 UTC.