如何按小时获取我的应用屏幕显示时间? [英] How can I get my app screen time on a hourly basis?

查看:122
本文介绍了如何按小时获取我的应用屏幕显示时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的UsageStatsManager返回至少一天的数据,但是我想从凌晨12点到当前时间获取准确的数据.我尝试了几种类型,但没有正常工作. 行动短跑"和数字健康"正在准确地获取数据.

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.

推荐答案

使用 queryEvents 方法"rel =" nofollow noreferrer> UsageStatsManager 类.

Use queryEvents method of UsageStatsManager class.

我最近建立了一个用于跟踪每日应用使用情况的应用.首先,我尝试使用 queryUsageStats ,但无法正常工作.我以为应该将使用时间从上午12点返回到当前时间,当 INTERVAL_DAILY 被传递给它,但是它返回了其他东西.也许是一个错误,或者我这边与时区有关的东西出了问题.

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.

无论如何,然后我尝试了 queryEvents ,效果很好.

Anyway, then I tried queryEvents and it worked fine.

这是我的​​实现 (请参阅问题和接受的答案).

Here's my implementation (See both the question and the accepted answer).

这篇关于如何按小时获取我的应用屏幕显示时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆