UsageEvents.Event

public static final class UsageEvents.Event
extends Object

java.lang.Object
   ↳ android.app.usage.UsageEvents.Event


An event representing a state change for a component.

Summary

Constants

int ACTIVITY_PAUSED

An event type denoting that an Activity moved to the background.

int ACTIVITY_RESUMED

An event type denoting that an Activity moved to the foreground.

int ACTIVITY_STOPPED

An activity becomes invisible on the UI, corresponding to Activity.onStop() of the activity's lifecycle.

int CONFIGURATION_CHANGE

An event type denoting that the device configuration has changed.

int DEVICE_SHUTDOWN

An event type denoting that the Android runtime underwent a shutdown process.

int DEVICE_STARTUP

An event type denoting that the Android runtime started up.

int FOREGROUND_SERVICE_START

An event type denoting start of a foreground service.

int FOREGROUND_SERVICE_STOP

An event type denoting stop of a foreground service.

int KEYGUARD_HIDDEN

An event type denoting that the screen's keyguard has been hidden.

int KEYGUARD_SHOWN

An event type denoting that the screen's keyguard has been shown, whether or not the screen is off.

int MOVE_TO_BACKGROUND

This constant was deprecated in API level 29. by ACTIVITY_PAUSED

int MOVE_TO_FOREGROUND

This constant was deprecated in API level 29. by ACTIVITY_RESUMED

int NONE

No event type.

int SCREEN_INTERACTIVE

An event type denoting that the screen has gone in to an interactive state (turned on for full user interaction, not ambient display or other non-interactive state).

int SCREEN_NON_INTERACTIVE

An event type denoting that the screen has gone in to a non-interactive state (completely turned off or turned on only in a non-interactive state like ambient display).

int SHORTCUT_INVOCATION

An event type denoting that an action equivalent to a ShortcutInfo is taken by the user.

int STANDBY_BUCKET_CHANGED

An event type denoting a change in App Standby Bucket.

int USER_INTERACTION

An event type denoting that a package was interacted with in some way by the user.

Public constructors

Event()

Public methods

int getAppStandbyBucket()

Returns the standby bucket of the app, if the event is of type STANDBY_BUCKET_CHANGED, otherwise returns 0.

String getClassName()

The class name of the source of this event.

Configuration getConfiguration()

Returns a Configuration for this event if the event is of type CONFIGURATION_CHANGE, otherwise it returns null.

int getEventType()

The event type.

PersistableBundle getExtras()

Retrieves a map of extended data from the event if the event is of type USER_INTERACTION.

String getPackageName()

The package name of the source of this event.

String getShortcutId()

Returns the ID of a ShortcutInfo for this event if the event is of type SHORTCUT_INVOCATION, otherwise it returns null.

long getTimeStamp()

The time at which this event occurred, measured in milliseconds since the epoch.

Inherited methods

Constants

ACTIVITY_PAUSED

Added in API level 29
public static final int ACTIVITY_PAUSED

An event type denoting that an Activity moved to the background. This event has a package name and class name associated with it and can be retrieved using getPackageName() and getClassName(). If a package has multiple activities, this event is reported for each activity that moves to background. This event is corresponding to Activity.onPause() of the activity's lifecycle.

Constant Value: 2 (0x00000002)

ACTIVITY_RESUMED

Added in API level 29
public static final int ACTIVITY_RESUMED

An event type denoting that an Activity moved to the foreground. This event has a package name and class name associated with it and can be retrieved using getPackageName() and getClassName(). If a package has multiple activities, this event is reported for each activity that moves to foreground. This event is corresponding to Activity.onResume() of the activity's lifecycle.

Constant Value: 1 (0x00000001)

ACTIVITY_STOPPED

Added in API level 29
public static final int ACTIVITY_STOPPED

An activity becomes invisible on the UI, corresponding to Activity.onStop() of the activity's lifecycle.

Constant Value: 23 (0x00000017)

CONFIGURATION_CHANGE

Added in API level 21
public static final int CONFIGURATION_CHANGE

An event type denoting that the device configuration has changed.

Constant Value: 5 (0x00000005)

DEVICE_SHUTDOWN

Added in API level 29
public static final int DEVICE_SHUTDOWN

An event type denoting that the Android runtime underwent a shutdown process. A DEVICE_SHUTDOWN event should be treated as if all started activities and foreground services are now stopped and no explicit ACTIVITY_STOPPED and FOREGROUND_SERVICE_STOP events will be generated for them.

The DEVICE_SHUTDOWN timestamp is actually the last time UsageStats database is persisted before the actual shutdown. Events (if there are any) between this timestamp and the actual shutdown is not persisted in the database. So any open events without matching close events between DEVICE_SHUTDOWN and DEVICE_STARTUP should be ignored because the closing time is unknown.

Constant Value: 26 (0x0000001a)

DEVICE_STARTUP

Added in API level 29
public static final int DEVICE_STARTUP

An event type denoting that the Android runtime started up. This could be after a shutdown or a runtime restart. Any open events without matching close events between DEVICE_SHUTDOWN and DEVICE_STARTUP should be ignored because the closing time is unknown.

Constant Value: 27 (0x0000001b)

FOREGROUND_SERVICE_START

Added in API level 29
public static final int FOREGROUND_SERVICE_START

An event type denoting start of a foreground service. This event has a package name and class name associated with it and can be retrieved using getPackageName() and getClassName(). If a package has multiple foreground services, this event is reported for each service that is started.

Constant Value: 19 (0x00000013)

FOREGROUND_SERVICE_STOP

Added in API level 29
public static final int FOREGROUND_SERVICE_STOP

An event type denoting stop of a foreground service. This event has a package name and class name associated with it and can be retrieved using getPackageName() and getClassName(). If a package has multiple foreground services, this event is reported for each service that is stopped.

Constant Value: 20 (0x00000014)

KEYGUARD_HIDDEN

Added in API level 28
public static final int KEYGUARD_HIDDEN

An event type denoting that the screen's keyguard has been hidden. This typically happens when the user unlocks their phone after turning it on.

Constant Value: 18 (0x00000012)

KEYGUARD_SHOWN

Added in API level 28
public static final int KEYGUARD_SHOWN

An event type denoting that the screen's keyguard has been shown, whether or not the screen is off.

Constant Value: 17 (0x00000011)

MOVE_TO_BACKGROUND

Added in API level 21
Deprecated in API level 29
public static final int MOVE_TO_BACKGROUND

This constant was deprecated in API level 29.
by ACTIVITY_PAUSED

Constant Value: 2 (0x00000002)

MOVE_TO_FOREGROUND

Added in API level 21
Deprecated in API level 29
public static final int MOVE_TO_FOREGROUND

This constant was deprecated in API level 29.
by ACTIVITY_RESUMED

Constant Value: 1 (0x00000001)

NONE

Added in API level 21
public static final int NONE

No event type.

Constant Value: 0 (0x00000000)

SCREEN_INTERACTIVE

Added in API level 28
public static final int SCREEN_INTERACTIVE

An event type denoting that the screen has gone in to an interactive state (turned on for full user interaction, not ambient display or other non-interactive state).

Constant Value: 15 (0x0000000f)

SCREEN_NON_INTERACTIVE

Added in API level 28
public static final int SCREEN_NON_INTERACTIVE

An event type denoting that the screen has gone in to a non-interactive state (completely turned off or turned on only in a non-interactive state like ambient display).

Constant Value: 16 (0x00000010)

SHORTCUT_INVOCATION

Added in API level 25
public static final int SHORTCUT_INVOCATION

An event type denoting that an action equivalent to a ShortcutInfo is taken by the user.

Constant Value: 8 (0x00000008)

STANDBY_BUCKET_CHANGED

Added in API level 28
public static final int STANDBY_BUCKET_CHANGED

An event type denoting a change in App Standby Bucket. The new bucket can be retrieved by calling getAppStandbyBucket().

Constant Value: 11 (0x0000000b)

USER_INTERACTION

Added in API level 23
public static final int USER_INTERACTION

An event type denoting that a package was interacted with in some way by the user.

Constant Value: 7 (0x00000007)

Public constructors

Event

Added in API level 21
public Event ()

Public methods

getAppStandbyBucket

Added in API level 28
public int getAppStandbyBucket ()

Returns the standby bucket of the app, if the event is of type STANDBY_BUCKET_CHANGED, otherwise returns 0.

Returns
int the standby bucket associated with the event.

getClassName

Added in API level 21
public String getClassName ()

The class name of the source of this event. This may be null for certain events.

Returns
String

getConfiguration

Added in API level 21
public Configuration getConfiguration ()

Returns a Configuration for this event if the event is of type CONFIGURATION_CHANGE, otherwise it returns null.

Returns
Configuration

getExtras

public PersistableBundle getExtras ()

Retrieves a map of extended data from the event if the event is of type USER_INTERACTION.

Returns
PersistableBundle the map of all extras that associated with the reported user interaction event. The returned PersistableBundle will contain the extras UsageStatsManager#EXTRA_EVENT_CATEGORY and UsageStatsManager#EXTRA_EVENT_ACTION. PersistableBundle#EMPTY will be returned if the details are not available. This value cannot be null.

getPackageName

Added in API level 21
public String getPackageName ()

The package name of the source of this event.

Returns
String

getShortcutId

Added in API level 25
public String getShortcutId ()

Returns the ID of a ShortcutInfo for this event if the event is of type SHORTCUT_INVOCATION, otherwise it returns null.

Returns
String

getTimeStamp

Added in API level 21
public long getTimeStamp ()

The time at which this event occurred, measured in milliseconds since the epoch.

See System#currentTimeMillis().
Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z.

Returns
long Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z.