lightbulb_outline Please take our October 2018 developer survey. Start survey

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

Represents voice command focus.

Public methods

void abandonAppFocus(CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback)

Abandon all focuses, i.e.

void abandonAppFocus(CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback, int appType)

Abandon the given focus, i.e.

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

Represents voice command focus.

Constant Value: 2 (0x00000002)

Public methods

abandonAppFocus

public void abandonAppFocus (CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback)

Abandon all focuses, i.e. mark them as inactive. This also involves releasing ownership for the focus.

Throws
CarNotConnectedException if the connection to the car service has been lost.

abandonAppFocus

public void abandonAppFocus (CarAppFocusManager.OnAppFocusOwnershipCallback ownershipCallback, 
                int appType)

Abandon the given focus, i.e. mark it as inactive. This also involves releasing ownership for the focus.

Throws
CarNotConnectedException if the connection to the car service has been lost.

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.

Throws
CarNotConnectedException if the connection to the car service has been lost.

isOwningFocus

public boolean isOwningFocus (CarAppFocusManager.OnAppFocusOwnershipCallback callback, 
                int appType)

Checks if listener is associated with active a focus

Returns
boolean

Throws
CarNotConnectedException if the connection to the car service has been lost.

removeFocusListener

public void removeFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener, 
                int appType)

Unregister listener for application type and stop listening focus change events.

Throws
CarNotConnectedException if the connection to the car service has been lost.

removeFocusListener

public void removeFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener)

Unregister listener and stop listening focus change events.

Throws
CarNotConnectedException if the connection to the car service has been lost.

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 CarAppFocusManager.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

Throws
CarNotConnectedException if the connection to the car service has been lost.
SecurityException If owner cannot be changed.