2

I am trying to write a way to get screen time for an entire year of using Android in general, not just a specific applications. I have the following code:

public double checkAppUsages() {
        UsageStatsManager usageStatsManager = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
        
        long time = System.currentTimeMillis();
        long delta = (31536000000L); // milliseconds in one year

        List<UsageStats> usageStatsList = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - delta, time);
        for (UsageStats stats : usageStatsList) {
            totalTime += stats.getTotalTimeInForeground(); 
        }
        return totalTime;
    }

This code finds the total time of using all apps. But I need the time of using smartphone in general.

Ryan M
  • 18,333
  • 31
  • 67
  • 74

0 Answers0