Added in API level 21

Event


class Event
kotlin.Any
   ↳ android.app.usage.UsageEvents.Event

An event representing a state change for a component.

Summary

Constants
static Int

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

static Int

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

static Int

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

static Int

An event type denoting that the device configuration has changed.

static Int

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

static Int

An event type denoting that the Android runtime started up.

static Int

An event type denoting start of a foreground service.

static Int

An event type denoting stop of a foreground service.

static Int

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

static Int

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

static Int

static Int

static Int

No event type.

static Int

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

static Int

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

static Int

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

static Int

An event type denoting a change in App Standby Bucket.

static Int

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

Public constructors

Public methods
Int

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

String!

The class name of the source of this event.

Configuration!

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

Int

The event type.

PersistableBundle

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

String!

The package name of the source of this event.

String!

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

Long

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

Constants

ACTIVITY_PAUSED

Added in API level 29
static val ACTIVITY_PAUSED: Int

An event type denoting that an android.app.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 android.app.Activity#onPause() of the activity's lifecycle.

Value: 2

ACTIVITY_RESUMED

Added in API level 29
static val ACTIVITY_RESUMED: Int

An event type denoting that an android.app.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 android.app.Activity#onResume() of the activity's lifecycle.

Value: 1

ACTIVITY_STOPPED

Added in API level 29
static val ACTIVITY_STOPPED: Int

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

Value: 23

CONFIGURATION_CHANGE

Added in API level 21
static val CONFIGURATION_CHANGE: Int

An event type denoting that the device configuration has changed.

Value: 5

DEVICE_SHUTDOWN

Added in API level 29
static val DEVICE_SHUTDOWN: Int

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.

Value: 26

DEVICE_STARTUP

Added in API level 29
static val DEVICE_STARTUP: Int

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.

Value: 27

FOREGROUND_SERVICE_START

Added in API level 29
static val FOREGROUND_SERVICE_START: Int

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.

Value: 19

FOREGROUND_SERVICE_STOP

Added in API level 29
static val FOREGROUND_SERVICE_STOP: Int

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.

Value: 20

KEYGUARD_HIDDEN

Added in API level 28
static val KEYGUARD_HIDDEN: Int

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.

Value: 18

KEYGUARD_SHOWN

Added in API level 28
static val KEYGUARD_SHOWN: Int

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

Value: 17

MOVE_TO_BACKGROUND

Added in API level 21
Deprecated in API level 29
static val MOVE_TO_BACKGROUND: Int

Deprecated: by ACTIVITY_PAUSED

Value: 2

MOVE_TO_FOREGROUND

Added in API level 21
Deprecated in API level 29
static val MOVE_TO_FOREGROUND: Int

Deprecated: by ACTIVITY_RESUMED

Value: 1

NONE

Added in API level 21
static val NONE: Int

No event type.

Value: 0

SCREEN_INTERACTIVE

Added in API level 28
static val SCREEN_INTERACTIVE: Int

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

Value: 15

SCREEN_NON_INTERACTIVE

Added in API level 28
static val SCREEN_NON_INTERACTIVE: Int

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

Value: 16

SHORTCUT_INVOCATION

Added in API level 25
static val SHORTCUT_INVOCATION: Int

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

Value: 8

STANDBY_BUCKET_CHANGED

Added in API level 28
static val STANDBY_BUCKET_CHANGED: Int

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

Value: 11

USER_INTERACTION

Added in API level 23
static val USER_INTERACTION: Int

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

Value: 7

Public constructors

Event

Added in API level 21
Event()

Public methods

getAppStandbyBucket

Added in API level 28
fun getAppStandbyBucket(): Int

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

Return
Int the standby bucket associated with the event.

getClassName

Added in API level 21
fun getClassName(): String!

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

getConfiguration

Added in API level 21
fun getConfiguration(): Configuration!

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

getExtras

Added in API level 35
fun getExtras(): PersistableBundle

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

Return
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
fun getPackageName(): String!

The package name of the source of this event.

getShortcutId

Added in API level 25
fun getShortcutId(): String!

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

getTimeStamp

Added in API level 21
fun getTimeStamp(): Long

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.
Return
Long Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z.