StatusBarManager  |  API reference  |  Android Developers


public class StatusBarManager
extends Object



Allows an app to control the status bar.

Summary

Constants

int SHOW_POWER_MENU_RESULT_DISABLED

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

int SHOW_POWER_MENU_RESULT_SHOWING

Result returned in a callback when a call to showPowerMenu(Executor, OutcomeReceiver) has succeeded and the Power Menu is currently showing.

int SHOW_POWER_MENU_RESULT_UNKNOWN

Unknwown result of calling showPowerMenu(Executor, OutcomeReceiver).

int TILE_ADD_REQUEST_ERROR_APP_NOT_IN_FOREGROUND

Indicates that the requesting application is not in the foreground.

int TILE_ADD_REQUEST_ERROR_BAD_COMPONENT

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

int TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE

Indicates that this package does not match that of the TileService.

int TILE_ADD_REQUEST_ERROR_NOT_CURRENT_USER

Indicates that the user is not the current user.

int TILE_ADD_REQUEST_ERROR_NO_STATUS_BAR_SERVICE

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

int TILE_ADD_REQUEST_ERROR_REQUEST_IN_PROGRESS

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

int TILE_ADD_REQUEST_RESULT_TILE_ADDED

Response indicating that the tile was added.

int TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED

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

int TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED

Response indicating that the tile was not added.

Public methods

boolean canLaunchCaptureContentActivityForNote(Activity activity)

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

void requestAddTileService(ComponentName tileServiceComponentName, CharSequence tileLabel, Icon icon, Executor resultExecutor, Consumer<Integer> resultCallback)

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

void showPowerMenu(Executor executor, OutcomeReceiver<IntegerThrowable> receiver)

Request to show the Power Menu.

Inherited methods

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Constants

public static final int SHOW_POWER_MENU_RESULT_DISABLED

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

Constant Value: 1 (0x00000001)

public static final int SHOW_POWER_MENU_RESULT_SHOWING

Result returned in a callback when a call to showPowerMenu(Executor, OutcomeReceiver) has succeeded and the Power Menu is currently showing.

Constant Value: 0 (0x00000000)

TILE_ADD_REQUEST_ERROR_APP_NOT_IN_FOREGROUND

public static final int TILE_ADD_REQUEST_ERROR_APP_NOT_IN_FOREGROUND

Indicates that the requesting application is not in the foreground.

Constant Value: 1004 (0x000003ec)

TILE_ADD_REQUEST_ERROR_BAD_COMPONENT

public static final int TILE_ADD_REQUEST_ERROR_BAD_COMPONENT

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

Constant Value: 1002 (0x000003ea)

TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE

public static final int TILE_ADD_REQUEST_ERROR_MISMATCHED_PACKAGE

Indicates that this package does not match that of the TileService.

Constant Value: 1000 (0x000003e8)

TILE_ADD_REQUEST_ERROR_NOT_CURRENT_USER

public static final int TILE_ADD_REQUEST_ERROR_NOT_CURRENT_USER

Indicates that the user is not the current user.

Constant Value: 1003 (0x000003eb)

TILE_ADD_REQUEST_ERROR_NO_STATUS_BAR_SERVICE

public static final int TILE_ADD_REQUEST_ERROR_NO_STATUS_BAR_SERVICE

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

Constant Value: 1005 (0x000003ed)

TILE_ADD_REQUEST_ERROR_REQUEST_IN_PROGRESS

public static final int TILE_ADD_REQUEST_ERROR_REQUEST_IN_PROGRESS

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

Constant Value: 1001 (0x000003e9)

TILE_ADD_REQUEST_RESULT_TILE_ADDED

public static final int TILE_ADD_REQUEST_RESULT_TILE_ADDED

Response indicating that the tile was added.

Constant Value: 2 (0x00000002)

TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED

public static final int TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED

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

Constant Value: 1 (0x00000001)

TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED

public static final int TILE_ADD_REQUEST_RESULT_TILE_NOT_ADDED

Response indicating that the tile was not added.

Constant Value: 0 (0x00000000)

Public methods

requestAddTileService

public void requestAddTileService (ComponentName tileServiceComponentName, 
                CharSequence tileLabel, 
                Icon icon, 
                Executor resultExecutor, 
                Consumer<Integer> resultCallback)

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

Calling this will prompt the user to decide whether they want to add the shown 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 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 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: callback to indicate the result of the request.
This value cannot be null.

showPowerMenu

public void showPowerMenu (Executor executor, 
                OutcomeReceiver<IntegerThrowable> receiver)

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 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 Manifest.permission.SHOW_POWER_MENU or 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: will call back with the result of the request, or a possible error.
This value cannot be null.
Value is one of the following: