public final class UsageStatsManager
extends Object
java.lang.Object | |
↳ | android.app.usage.UsageStatsManager |
提供对设备使用历史和统计数据的访问。 使用情况数据汇总为时间间隔:天,周,月和年。
When requesting usage data since a particular time, the request might look something like this:PAST REQUEST_TIME TODAY FUTURE ————————————————————————————||———————————————————————————¦-----------------------| YEAR || ¦ | ————————————————————————————||———————————————————————————¦-----------------------| MONTH | || MONTH ¦ | ——————————————————|—————————||———————————————————————————¦-----------------------| | WEEK | WEEK|| | WEEK | WE¦EK | WEEK | ————————————————————————————||———————————————————|———————¦-----------------------| || |DAY|DAY|DAY|DAY¦DAY|DAY|DAY|DAY|DAY|DAY| ————————————————————————————||———————————————————————————¦-----------------------|A request for data in the middle of a time interval will include that interval. NOTE: This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.
Constants |
|
---|---|
int |
INTERVAL_BEST 间隔类型将使用给定时间范围内的最佳拟合间隔。 |
int |
INTERVAL_DAILY 跨越一天的间隔类型。 |
int |
INTERVAL_MONTHLY 跨越一个月的间隔类型。 |
int |
INTERVAL_WEEKLY 跨越一周的间隔类型。 |
int |
INTERVAL_YEARLY 跨越一年的间隔类型。 |
Public methods |
|
---|---|
boolean |
isAppInactive(String packageName) 返回指定的应用程序当前是否被视为不活动。 |
Map<String, UsageStats> |
queryAndAggregateUsageStats(long beginTime, long endTime) 查询给定范围内的所有统计数据(使用该范围内的最佳时间间隔)的便捷方法,合并结果数据,并按包名键入。 |
List<ConfigurationStats> |
queryConfigurations(int intervalType, long beginTime, long endTime) 获取设备在给定时间范围内的硬件配置,按照指定的时间间隔进行聚合。 |
UsageEvents |
queryEvents(long beginTime, long endTime) 查询给定时间范围内的事件。 |
List<UsageStats> |
queryUsageStats(int intervalType, long beginTime, long endTime) 获取给定时间范围内的应用程序使用统计信息,并按指定的时间间隔进行聚合。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
int INTERVAL_BEST
间隔类型将使用给定时间范围内的最佳拟合间隔。 见queryUsageStats(int, long, long)
。
常量值:4(0x00000004)
int INTERVAL_DAILY
跨越一天的间隔类型。 见queryUsageStats(int, long, long)
。
常量值:0(0x00000000)
int INTERVAL_MONTHLY
跨越一个月的间隔类型。 见queryUsageStats(int, long, long)
。
常量值:2(0x00000002)
int INTERVAL_WEEKLY
跨越一周的间隔类型。 见queryUsageStats(int, long, long)
。
常数值:1(0x00000001)
int INTERVAL_YEARLY
跨越一年的间隔类型。 见queryUsageStats(int, long, long)
。
常量值:3(0x00000003)
boolean isAppInactive (String packageName)
返回指定的应用程序当前是否被视为不活动。 如果应用程序未在系统定义的一段时间内直接或间接使用,情况将会如此。 这可能是几个小时或几天的量级。
Parameters | |
---|---|
packageName |
String : The package name of the app to query |
Returns | |
---|---|
boolean |
whether the app is currently considered inactive |
Map<String, UsageStats> queryAndAggregateUsageStats (long beginTime, long endTime)
查询给定范围内的所有统计数据(使用该范围内的最佳时间间隔)的便捷方法,合并结果数据,并按包名键入。 见queryUsageStats(int, long, long)
。
Parameters | |
---|---|
beginTime |
long : The inclusive beginning of the range of stats to include in the results. |
endTime |
long : The exclusive end of the range of stats to include in the results. |
Returns | |
---|---|
Map<String, UsageStats> |
A Map keyed by package name, or null if no stats are available. |
List<ConfigurationStats> queryConfigurations (int intervalType, long beginTime, long endTime)
获取设备在给定时间范围内的硬件配置,按照指定的时间间隔进行聚合。 结果按照queryUsageStats(int, long, long)
顺序queryUsageStats(int, long, long)
。
Parameters | |
---|---|
intervalType |
int : The time interval by which the stats are aggregated. |
beginTime |
long : The inclusive beginning of the range of stats to include in the results. |
endTime |
long : The exclusive end of the range of stats to include in the results. |
Returns | |
---|---|
List<ConfigurationStats> |
A list of ConfigurationStats or null if none are available. |
UsageEvents queryEvents (long beginTime, long endTime)
查询给定时间范围内的事件。 事件只能由系统保留几天。
NOTE: The last few minutes of the event log will be truncated to prevent abuse by applications.Parameters | |
---|---|
beginTime |
long : The inclusive beginning of the range of events to include in the results. |
endTime |
long : The exclusive end of the range of events to include in the results. |
Returns | |
---|---|
UsageEvents |
A UsageEvents . |
List<UsageStats> queryUsageStats (int intervalType, long beginTime, long endTime)
获取给定时间范围内的应用程序使用统计信息,并按指定的时间间隔进行聚合。
返回的列表将包含每个数据包的UsageStats
对象,该数据包的时间间隔是给定时间范围的子集。 为了显示:
intervalType = INTERVAL_YEARLY beginTime = 2013 endTime = 2015 (exclusive) Results: 2013 - com.example.alpha 2013 - com.example.beta 2014 - com.example.alpha 2014 - com.example.beta 2014 - com.example.charlie
Parameters | |
---|---|
intervalType |
int : The time interval by which the stats are aggregated. |
beginTime |
long : The inclusive beginning of the range of stats to include in the results. |
endTime |
long : The exclusive end of the range of stats to include in the results. |
Returns | |
---|---|
List<UsageStats> |
A list of UsageStats or null if none are available. |