问题
Android's UsageStatsManager returning data for minimum one day, but I want to get accurate data from 12 am to the current time. I tried several types but nothing works properly. The "Action Dash" and "Digital Wellbeing" is getting data accurately.
回答1:
Use queryEvents method of UsageStatsManager class.
I've recently built an app for tracking daily app usage. Firstly, I tried using queryUsageStats but it didn't work properly. I thought it was supposed to return usage time from 12 am to current time when INTERVAL_DAILY is passed to it, but instead it was returning something else. Maybe there is a bug or there is something wrong on my side related to time zone or something.
Anyway, then I tried queryEvents and it worked fine.
Here's my implementation (See both the question and the accepted answer).
来源:https://stackoverflow.com/questions/61615457/how-can-i-get-my-app-screen-time-on-a-hourly-basis