Android APIs
public final class

UsageStats

extends Object
implements Parcelable
java.lang.Object
   ↳ android.app.usage.UsageStats

Class Overview

Contains usage statistics for an app package for a specific time range.

Summary

[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<UsageStats> CREATOR
Public Constructors
UsageStats(UsageStats stats)
Public Methods
void add(UsageStats right)
Add the statistics from the right UsageStats to the left.
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
long getFirstTimeStamp()
Get the beginning of the time range this UsageStats represents, measured in milliseconds since the epoch.
long getLastTimeStamp()
Get the end of the time range this UsageStats represents, measured in milliseconds since the epoch.
long getLastTimeUsed()
Get the last time this package was used, measured in milliseconds since the epoch.
String getPackageName()
long getTotalTimeInForeground()
Get the total time this package spent in the foreground, measured in milliseconds.
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Fields

public static final Creator<UsageStats> CREATOR

Added in API level 21

Public Constructors

public UsageStats (UsageStats stats)

Added in API level 21

Public Methods

public void add (UsageStats right)

Added in API level 21

Add the statistics from the right UsageStats to the left. The package name for both UsageStats objects must be the same.

Parameters
right The UsageStats object to merge into this one.
Throws
IllegalArgumentException if the package names of the two UsageStats objects are different.

public int describeContents ()

Added in API level 21

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public long getFirstTimeStamp ()

Added in API level 21

Get the beginning of the time range this UsageStats represents, measured in milliseconds since the epoch.

See currentTimeMillis().

public long getLastTimeStamp ()

Added in API level 21

Get the end of the time range this UsageStats represents, measured in milliseconds since the epoch.

See currentTimeMillis().

public long getLastTimeUsed ()

Added in API level 21

Get the last time this package was used, measured in milliseconds since the epoch.

See currentTimeMillis().

public String getPackageName ()

Added in API level 21

public long getTotalTimeInForeground ()

Added in API level 21

Get the total time this package spent in the foreground, measured in milliseconds.

public void writeToParcel (Parcel dest, int flags)

Added in API level 21

Flatten this object in to a Parcel.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.