List of usage examples for android.app.usage UsageStats getTotalTimeInForeground
public long getTotalTimeInForeground()
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; }