Added in API level 29

StatusBarManager


open class StatusBarManager
kotlin.Any
   ↳ android.app.StatusBarManager

Allows an app to control the status bar.

Summary

Constants
static String

Intent action to identify the defaults to use for the agent task space.

static Int

Result returned in a callback when a call to showPowerMenu cannot be completed due to the Power Menu being currently disabled.

static Int

Result returned in a callback when a call to showPowerMenu has succeeded and the Power Menu is currently showing.

static Int

Unknwown result of calling showPowerMenu.

static Int

Indicates that the requesting application is not in the foreground.

static Int

Indicates that the component does not match an enabled exported android.service.quicksettings.TileService for the current user.

static Int

Indicates that this package does not match that of the android.service.quicksettings.TileService.

static Int

Indicates that the user is not the current user.

static Int

The request could not be processed because no fulfilling service was found.

static Int

Indicates that there's a request in progress for this package.

static Int

Response indicating that the tile was added.

static Int

Response indicating that the tile was already added and the user was not prompted.

static Int

Response indicating that the tile was not added.

Public methods
open Boolean

Checks whether the supplied activity can Activity.startActivityForResult(Intent,int) a system activity that captures content on the screen to take a screenshot.

open Boolean

Indicates whether the caller can currently set agent tasks in the status bar.

open Rect?

Fetches the absolute on-screen bounds of the agent task state UI for the given display.

open Boolean

Returns whether the agent task status icon feature is supported by this device configuration.

open Boolean

Returns whether the agent task feature supports interacting with its elements to launch activities.

open Unit
requestAddTileService(tileServiceComponentName: ComponentName, tileLabel: CharSequence, icon: Icon, resultExecutor: Executor, resultCallback: Consumer<Int!>)

Request to the user to add a android.service.quicksettings.TileService to the set of current QS tiles.

open Unit
setAgentTask(request: AgentTaskUpdate?, executor: Executor, outcomeReceiver: OutcomeReceiver<AgentTaskOutcome!, Throwable!>)

Requests that a specific Agent Task be shown in the corresponding space.

open Unit
showPowerMenu(executor: Executor, receiver: OutcomeReceiver<Int!, Throwable!>)

Request to show the Power Menu.

Constants

ACTION_AGENT_TASK_MAIN

static val ACTION_AGENT_TASK_MAIN: String

Intent action to identify the defaults to use for the agent task space.

Adding this action to the intent-filter of a component in the Manifest will set that as the default icon and action to launch before a call to setAgentTask with a non null AgentTaskState is made. This is effectively the default state.

Default icons will not be animated, unlike icons for active tasks.

In order to revert to this state, call setAgentTask with a null request.

Having an activity with this intent-filter is a requirement to be able to use the setAgentTask API.

Example use:

<activity
     android:name=".MyAgentActivity"
     android:icon="@drawable/my_default_icon">
     <intent-filter>
        <action android:name="android.app.action.AGENT_TASK_MAIN" />
     </intent-filter>
  </activity>
  
Value: "android.app.action.AGENT_TASK_MAIN"

SHOW_POWER_MENU_RESULT_DISABLED

Added in API level 37
static val SHOW_POWER_MENU_RESULT_DISABLED: Int

Result returned in a callback when a call to showPowerMenu cannot be completed due to the Power Menu being currently disabled.

Value: 1

SHOW_POWER_MENU_RESULT_SHOWING

Added in API level 37
static val SHOW_POWER_MENU_RESULT_SHOWING: Int

Result returned in a callback when a call to showPowerMenu has succeeded and the Power Menu is currently showing.

Value: 0

SHOW_POWER_MENU_RESULT_UNKNOWN

Added in API level 37
static val SHOW_POWER_MENU_RESULT_UNKNOWN: Int

Unknwown result of calling showPowerMenu. Used for compatibility purposes.

Value: -1

TILE_ADD_REQUEST_ERROR_APP_NOT_IN_FOREGROUND

Added in API level 33
static val TILE_ADD_REQUEST_ERROR_APP_NOT_IN_FOREGROUND: Int

Indicates that the requesting application is not in the foreground.

Value: 1004

TILE_ADD_REQUEST_ERROR_BAD_COMPONENT

Added in API level 33
static val TILE_ADD_REQUEST_ERROR_BAD_COMPONENT: Int

Indicates that the component does not match an enabled exported android.service.quicksettings.TileService for the current user.

Value: 1002

TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE

Added in API level 33
static val TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE: Int

Indicates that this package does not match that of the android.service.quicksettings.TileService.

Value: 1000

TILE_ADD_REQUEST_ERROR_NOT_CURRENT_USER

Added in API level 33
static val TILE_ADD_REQUEST_ERROR_NOT_CURRENT_USER: Int

Indicates that the user is not the current user.

Value: 1003

TILE_ADD_REQUEST_ERROR_NO_STATUS_BAR_SERVICE

Added in API level 33
static val TILE_ADD_REQUEST_ERROR_NO_STATUS_BAR_SERVICE: Int

The request could not be processed because no fulfilling service was found. This could be a temporary issue (for example, SystemUI has crashed).

Value: 1005

TILE_ADD_REQUEST_ERROR_REQUEST_IN_PROGRESS

Added in API level 33
static val TILE_ADD_REQUEST_ERROR_REQUEST_IN_PROGRESS: Int

Indicates that there's a request in progress for this package.

Value: 1001

TILE_ADD_REQUEST_RESULT_TILE_ADDED

Added in API level 33
static val TILE_ADD_REQUEST_RESULT_TILE_ADDED: Int

Response indicating that the tile was added.

Value: 2

TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED

Added in API level 33
static val TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED: Int

Response indicating that the tile was already added and the user was not prompted.

Value: 1

TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED

Added in API level 33
static val TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED: Int

Response indicating that the tile was not added.

Value: 0

Public methods

canLaunchCaptureContentActivityForNote

Added in API level 34
open fun canLaunchCaptureContentActivityForNote(activity: Activity): Boolean

Checks whether the supplied activity can Activity.startActivityForResult(Intent,int) a system activity that captures content on the screen to take a screenshot.

Note: The result should not be cached.

The system activity displays an editing tool that allows user to edit the screenshot, save it on device, and return the edited screenshot as android.net.Uri to the calling activity. User interaction is required to return the edited screenshot to the calling activity.

When true, callers can use Activity.startActivityForResult(Intent,int) to start start the content capture activity using Intent.ACTION_LAUNCH_CAPTURE_CONTENT_ACTIVITY_FOR_NOTE.
Requires android.Manifest.permission#LAUNCH_CAPTURE_CONTENT_ACTIVITY_FOR_NOTE

Parameters
activity Activity: Calling activity.
This value cannot be null.
Return
Boolean true if the activity supports launching the capture content activity for note.

canSetAgentTask

open fun canSetAgentTask(): Boolean

Indicates whether the caller can currently set agent tasks in the status bar.

In order for a caller to be able to do this, the following must be true:

Return
Boolean true if this app can currently send requests to modify the agents space, and the user has currently authorized this.

getAgentStateScreenLocation

open fun getAgentStateScreenLocation(displayId: Int): Rect?

Fetches the absolute on-screen bounds of the agent task state UI for the given display. If an android.agenticon.AgentTaskEvent is showing, then this method will return the on-screen bounds of the android.agenticon.AgentTaskState underneath, *not* the bounds of the temporary event.
This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
displayId Int: the ID of the display to query for the on-screen location.
Return
Rect? the absolute on-screen bounds of the agent state icon for the given display. Returns null if agent task state is not visible on the given display or if there was a problem fetching the value.
Exceptions
java.util.concurrent.ExecutionException if the calling package is not able to control agent tasks (see canSetAgentTask), or if there was an error fetching the value.

isAgentTaskFeatureSupported

open fun isAgentTaskFeatureSupported(): Boolean

Returns whether the agent task status icon feature is supported by this device configuration.

Return
Boolean true if the feature is supported, false otherwise.

isAgentTaskLaunchSupported

open fun isAgentTaskLaunchSupported(): Boolean

Returns whether the agent task feature supports interacting with its elements to launch activities.

If this is false, PendingIntent set in Agent Task classes (for example AgentTaskState.getClickAction) will be ignored.

Return
Boolean true if the agent task feature is supported and this implementation supports interacting with elements to launch activities.

requestAddTileService

Added in API level 33
open fun requestAddTileService(
    tileServiceComponentName: ComponentName,
    tileLabel: CharSequence,
    icon: Icon,
    resultExecutor: Executor,
    resultCallback: Consumer<Int!>
): Unit

Request to the user to add a android.service.quicksettings.TileService to the set of current QS tiles.

Calling this will prompt the user to decide whether they want to add the shown android.service.quicksettings.TileService to their current tiles. The user can deny the request and the system can stop processing requests for a given ComponentName after a number of requests.

The request will show to the user information about the tile:

  • Application name
  • Label for the tile
  • Icon for the tile

The user for which this will be added is determined from the Context used to retrieve this service, and must match the current user. The requesting application must be in the foreground (ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND and the android.service.quicksettings.TileService must be exported. Note: the system can choose to auto-deny a request if the user has denied that specific request (user, ComponentName) enough times before.

Parameters
tileServiceComponentName ComponentName: ComponentName of the android.service.quicksettings.TileService for the request.
This value cannot be null.
tileLabel CharSequence: label of the tile to show to the user.
This value cannot be null.
icon Icon: icon to use in the tile shown to the user.
This value cannot be null.
resultExecutor Executor: an executor to run the callback on.
This value cannot be null.
resultCallback Consumer<Int!>: callback to indicate the result of the request.
This value cannot be null.

setAgentTask

open fun setAgentTask(
    request: AgentTaskUpdate?,
    executor: Executor,
    outcomeReceiver: OutcomeReceiver<AgentTaskOutcome!, Throwable!>
): Unit

Requests that a specific Agent Task be shown in the corresponding space.

Requests will be performed on a best effort basis, with the last request sent taking precedence in case of multiple simultaneous requests.

If the request is meant to accompany a Notification, the correct values should be set to hide the Notification icon in the status bar (see Notification.Builder.setAgentInteractionFlags)

The default state icon and action should be set in the Manifest, using ACTION_AGENT_TASK_MAIN.

A null request will reset the state to the default, as defined using ACTION_AGENT_TASK_MAIN. This will immediately cancel current and pending state icon animations (see AgentTaskState) and events (see AgentTaskEvent).

This operation can only be performed for the current user. Trying to set an update for a user that is not the current user will not succeed.

Parameters
request AgentTaskUpdate?: the agent task information to show to the user, or null to reset to default
executor Executor: an executor for calling into outcomeReceiver
This value cannot be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
outcomeReceiver OutcomeReceiver<AgentTaskOutcome!, Throwable!>: a callback for receiving the result of the request, or an error if the call could not be processed.
This value cannot be null.

showPowerMenu

Added in API level 37
open fun showPowerMenu(
    executor: Executor,
    receiver: OutcomeReceiver<Int!, Throwable!>
): Unit

Request to show the Power Menu.

The Power Menu is the dialog that contains options like Power off, Restart, etc. Also known as Global Actions

Showing this dialog may be restricted by the system, for example by DevicePolicyManager, if DevicePolicyManager.LOCK_TASK_FEATURE_GLOBAL_ACTIONS is set.

The receiver will indicate when the Power Menu is visible (if possible) in its result, or whether the Power Menu is currently disabled. If the Power Menu is currently visible when the request is made, SHOW_POWER_MENU_RESULT_SHOWING will be returned through the callback immediately.

Alternatively, if the request could not be completed due to an error, it will be returned with OutcomeReceiver.onError. This error can be java.util.concurrent.TimeoutException if the request times out after a few seconds without a response, or a different Exception. In these error cases, it usually means that there's an underlying issue with the system and retrying will not succeed.

This callback can be reused for multiple requests.
Requires android.Manifest.permission#SHOW_POWER_MENU or android.Manifest.permission#SHOW_POWER_MENU_PRIVILEGED

Parameters
executor Executor: an Executor in which the methods of callback will be called.
This value cannot be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
receiver OutcomeReceiver<Int!, Throwable!>: will call back with the result of the request, or a possible error.
This value cannot be null.
Value is one of the following: