# CarAppFocusManager

Summary:[Nested Classes](https://developer.android.com/reference/android/car/CarAppFocusManager#nestedclasses)\|[Constants](https://developer.android.com/reference/android/car/CarAppFocusManager#constants)\|[Methods](https://developer.android.com/reference/android/car/CarAppFocusManager#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/car/CarAppFocusManager#inhmethods)  

# CarAppFocusManager

`
public

final

class
CarAppFocusManager
`  
`

extends Object


``


`

|---|--------------------------------|
| java.lang.Object                  ||
| ↳ | android.car.CarAppFocusManager |

<br />

*** ** * ** ***

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](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusChangedListener) Listener to get notification for app getting information on application type status changes. |
| ` interface` | [CarAppFocusManager.OnAppFocusOwnershipCallback](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusOwnershipCallback) Listener to get notification for app getting information on app type ownership loss.     |

|                                                                                                                                             ### Constants                                                                                                                                             ||
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [APP_FOCUS_REQUEST_FAILED](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_REQUEST_FAILED) A failed focus change request.                                                                                                                                     |
| `int` | [APP_FOCUS_REQUEST_SUCCEEDED](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_REQUEST_SUCCEEDED) A successful focus change request.                                                                                                                           |
| `int` | [APP_FOCUS_TYPE_NAVIGATION](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION) Represents navigation focus.                                                                                                                                     |
| `int` | [APP_FOCUS_TYPE_VOICE_COMMAND](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_TYPE_VOICE_COMMAND) *This constant is deprecated. use[VoiceInteractionService](https://developer.android.com/reference/android/service/voice/VoiceInteractionService)instead.* |

|                                                                                                                                                                                                                       ### Public methods                                                                                                                                                                                                                        ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`    | ` `[abandonAppFocus](https://developer.android.com/reference/android/car/CarAppFocusManager#abandonAppFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipCallback))`(`[CarAppFocusManager.OnAppFocusOwnershipCallback](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusOwnershipCallback)` ownershipCallback) ` Abandons all focuses, marking them as inactive.                                               |
| ` void`    | ` `[abandonAppFocus](https://developer.android.com/reference/android/car/CarAppFocusManager#abandonAppFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipCallback,%20int))`(`[CarAppFocusManager.OnAppFocusOwnershipCallback](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusOwnershipCallback)` ownershipCallback, int appType) ` Abandons the given focus, marking it as inactive.                         |
| ` void`    | ` `[addFocusListener](https://developer.android.com/reference/android/car/CarAppFocusManager#addFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener,%20int))`(`[CarAppFocusManager.OnAppFocusChangedListener](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusChangedListener)` listener, int appType) ` Register listener to monitor app focus change.                                         |
| ` boolean` | ` `[isOwningFocus](https://developer.android.com/reference/android/car/CarAppFocusManager#isOwningFocus(android.car.CarAppFocusManager.OnAppFocusOwnershipCallback,%20int))`(`[CarAppFocusManager.OnAppFocusOwnershipCallback](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusOwnershipCallback)` callback, int appType) ` Checks if listener is associated with active a focus                                   |
| ` void`    | ` `[removeFocusListener](https://developer.android.com/reference/android/car/CarAppFocusManager#removeFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener))`(`[CarAppFocusManager.OnAppFocusChangedListener](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusChangedListener)` listener) ` Unregister listener and stop listening focus change events.                                          |
| ` void`    | ` `[removeFocusListener](https://developer.android.com/reference/android/car/CarAppFocusManager#removeFocusListener(android.car.CarAppFocusManager.OnAppFocusChangedListener,%20int))`(`[CarAppFocusManager.OnAppFocusChangedListener](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusChangedListener)` listener, int appType) ` Unregister listener for application type and stop listening focus change events. |
| ` int`     | ` `[requestAppFocus](https://developer.android.com/reference/android/car/CarAppFocusManager#requestAppFocus(int,%20android.car.CarAppFocusManager.OnAppFocusOwnershipCallback))`(int appType, `[CarAppFocusManager.OnAppFocusOwnershipCallback](https://developer.android.com/reference/android/car/CarAppFocusManager.OnAppFocusOwnershipCallback)` ownershipCallback) ` Requests application focus.                                               |

| ### Inherited methods |
|-----------------------|---|
| From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Constants

### APP_FOCUS_REQUEST_FAILED

```
public static final int APP_FOCUS_REQUEST_FAILED
```

A failed focus change request.

<br />

Constant Value: 0 (0x00000000)  

### APP_FOCUS_REQUEST_SUCCEEDED

```
public static final int APP_FOCUS_REQUEST_SUCCEEDED
```

A successful focus change request.

<br />

Constant Value: 1 (0x00000001)  

### APP_FOCUS_TYPE_NAVIGATION

```
public static final int APP_FOCUS_TYPE_NAVIGATION
```

Represents navigation focus.

<br />

Constant Value: 1 (0x00000001)  

### APP_FOCUS_TYPE_VOICE_COMMAND

```
public static final int APP_FOCUS_TYPE_VOICE_COMMAND
```

<br />

**This constant is deprecated.**   
use[VoiceInteractionService](https://developer.android.com/reference/android/service/voice/VoiceInteractionService)instead.

Represents voice command focus.

<br />

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.

<br />

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

<br />

|                                                                           Parameters                                                                           ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `appType` | `int`: Value is[APP_FOCUS_TYPE_NAVIGATION](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION) <br /> |

### addFocusListener

```
public void addFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener, 
                int appType)
```

Register listener to monitor app focus change.

<br />

|                                                                                                Parameters                                                                                                ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `appType` | `int`: Application type to get notification for. Value is[APP_FOCUS_TYPE_NAVIGATION](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION) <br /> |

### isOwningFocus

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

Checks if listener is associated with active a focus

<br />

|                                                                           Parameters                                                                           ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `appType` | `int`: Value is[APP_FOCUS_TYPE_NAVIGATION](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION) <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### removeFocusListener

```
public void removeFocusListener (CarAppFocusManager.OnAppFocusChangedListener listener)
```

Unregister listener and stop listening focus change events.

<br />

### removeFocusListener

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

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

<br />

|                                                                           Parameters                                                                           ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `appType` | `int`: Value is[APP_FOCUS_TYPE_NAVIGATION](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION) <br /> |

### 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)](https://developer.android.com/reference/android/car/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.

<br />

|                                                                                                                                                                                                                                                                       Returns                                                                                                                                                                                                                                                                        ||
|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [APP_FOCUS_REQUEST_FAILED](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_REQUEST_FAILED)or[APP_FOCUS_REQUEST_SUCCEEDED](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_REQUEST_SUCCEEDED)Value is[APP_FOCUS_REQUEST_FAILED](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_REQUEST_FAILED), or[APP_FOCUS_REQUEST_SUCCEEDED](https://developer.android.com/reference/android/car/CarAppFocusManager#APP_FOCUS_REQUEST_SUCCEEDED) <br /> |

|                      Throws                      ||
|---------------------|-----------------------------|
| `SecurityException` | If owner cannot be changed. |