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 VoiceInteractionService instead.

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

Added in API level 29
public static final int APP_FOCUS_REQUEST_FAILED

A failed focus change request.

Constant Value: 0 (0x00000000)

APP_FOCUS_REQUEST_SUCCEEDED

Added in API level 29
public static final int APP_FOCUS_REQUEST_SUCCEEDED

A successful focus change request.

Constant Value: 1 (0x00000001)

APP_FOCUS_TYPE_NAVIGATION

Added in API level 29
public static final int APP_FOCUS_TYPE_NAVIGATION

Represents navigation focus.

Constant Value: 1 (0x00000001)

APP_FOCUS_TYPE_VOICE_COMMAND

Added in API level 29
Deprecated in API level 29
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

Added in API level 29
public void abandonAppFocus (CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback)

Abandons all focuses, marking them as inactive. This also involves releasing ownership for the focus.

abandonAppFocus

Added in API level 29
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

Added in API level 29
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

Added in API level 29
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

Added in API level 29
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

Added in API level 29
public void removeFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener)

Unregister listener and stop listening focus change events.

requestAppFocus

Added in API level 29
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.