Example usage for android.app.usage UsageStats getTotalTimeInForeground

List of usage examples for android.app.usage UsageStats getTotalTimeInForeground

Introduction

In this page you can find the example usage for android.app.usage UsageStats getTotalTimeInForeground.

Prototype

public long getTotalTimeInForeground() 

Source Link

Document

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

Usage

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private List<AppEntry> getAppEntriesUsingUsageStats() {
    UsageStatsManager mUsageStatsManager = (UsageStatsManager) getSystemService(USAGE_STATS_SERVICE);
    List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_YEARLY,
            searchInterval, System.currentTimeMillis());
    List<AppEntry> entries = new ArrayList<>();

    for (UsageStats usageStats : usageStatsList) {
        AppEntry newEntry = new AppEntry(usageStats.getPackageName(), null, null, null, false);

        newEntry.setTotalTimeInForeground(usageStats.getTotalTimeInForeground());
        newEntry.setLastTimeUsed(usageStats.getLastTimeUsed());
        entries.add(newEntry);/*from w  w w  .java 2s . c  om*/
    }

    return entries;
}