问题标签 [usagestatsmanager]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
219 浏览

java - Android UsageStats INTERVAL_DAILY 不起作用

我试图在当天从 UsageStats 获取 totalTimeInForeground,我的代码是:

问题是它正在检索前一天的数据,即使getFirstTimeStamp也是前一天的数据。

我知道以前有人问过这个问题,这是一个常见问题,但在我的研究中我没有找到任何具体的解决方案。

谢谢指教。

0 投票
2 回答
624 浏览

java - 如何在此应用程序中添加在前台花费的总时间而不是上次使用的时间?

我是 Java 和 Android 工作室的新手,这是来自未知来源的源代码。我需要显示应用程序在前台使用的总时间,而不是上次使用的时间,所以有人可以提一下我为实现目标需要进行的必要更改。提前致谢。

DateUtils.java

MainActivity.java

UsagePresenter.java

UsageStatAdapter.java

UsageStatsWrapper.java

UsageStatVH.java

截图 示例图像

0 投票
1 回答
1406 浏览

android - Android P:UsageStatsManager getAppStandbyBucket

我想使用 Android P beta 下的设备显示我的应用程序的当前存储桶。因此,我尝试像这样使用 UsageStatsManager 类:

我的清单拥有权限 android.permission.PACKAGE_USAGE_STATS :

但是当我启动我的应用程序时遇到了崩溃:

似乎我错过了一个权限,但即使我添加了以下权限:

我仍然有同样的崩溃。我在想也许我错过了权限的运行时调用,但就像文档规定的那样:

注意:此 API 上的大多数方法都需要权限 android.permission.PACKAGE_USAGE_STATS。但是,声明权限意味着使用 API 的意图,并且设备的用户仍然需要通过设置应用程序授予权限。请参阅 Settings.ACTION_USAGE_ACCESS_SETTINGS。只返回调用包信息的方法不需要此权限。例如getAppStandbyBucket () 和 queryEventsForSelf(long, long)。

这不是必需的。即使知道我尝试使用运行时权限,但我仍然会崩溃。如果有人看到缺少什么,我将非常感谢您的帮助。

0 投票
1 回答
406 浏览

android - getAppStandbyBucket 需要未知权限

当我尝试使用 UsageStatsManager.getAppStandbyBucket 获取新的 Android 8(或 P)应用程序备用存储桶时,我收到此错误,为应用程序提供了所有可能的权限,但仍然崩溃:

java.lang.SecurityException: MATCH_ANY_USER 标志需要 com.android.server.pm.PackageManagerService.getPackageUid:4959 com.android.server.pm.PackageManagerService$PackageManagerInternalImpl.getPackageUid:25142 com.android.server.usage.UsageStatsService$ 的 INTERACT_ACROSS_USERS 权限BinderService.getAppStandbyBucket:932 android.app.usage.IUsageStatsManager$Stub.onTransact:274 android.os.Binder.execTransact:731:用户 10228 和当前进程都没有 android.permission.INTERACT_ACROSS_USERS。

0 投票
0 回答
136 浏览

android - Daily Usagestats files somehow updating the file's name

I am currently investigating the files of /data/system/usagestats/0/daily of an Android phone (version 6.0.1).

I have saved the daily files from the android phone with the adb pull-command every day, starting from the 05.08.18 up to 12.08.18. As far as I know, the phone keeps the daily files for seven days.
In the picture, you can see the file from the 05.08. that I saved manually. Seven days later the file is still in the "daily"-folder but now has a different file name as you can see in the picture, whereas the content stayed the same.
To get the correct timestamp of each event, you have to add the number from last time active to the file's name. But in this case, you get a wrong result (difference of two seconds), because somehow the file's name updated.

Does anyone have any idea what is causing this time difference?

Picture of file names

0 投票
1 回答
45 浏览

android - 如何使用 PACKAGE_USAGE_STATS 权限从浏览器获取用户输入的 url?

我想获取用户在浏览器上键入的浏览器 url(来自所有浏览器,即哪个浏览器使用他们的手机)。我可以使用 AccessibilityService 获取该 URL。我只是想知道如何在 android 中使用 PACKAGE_USAGE_STATS 权限获取 url。

0 投票
0 回答
51 浏览

android - UsageStatsManager 没有为时间间隔提供适当的数据

使用UsageStatsManager我正在尝试从上午 12 点到当前时间获取数据。我写了以下代码:

但提供的结果每 4 或 6 小时重置一次;比如早上 6 点、中午 12 点、下午 4 点、中午 12 点。这里有什么问题?

0 投票
1 回答
313 浏览

java - 了解 UsageStats 和 UsageStatsManager 数据

任何人都可以帮助我了解 UsageStats 数据。UsageStatsManager.INTERVAL_MONTHLY 的目的是什么,因为我在天间隔内获取数据。

代码

结果

p>

0 投票
2 回答
294 浏览

android - Android 使用统计返回奇怪的结果

我正在查看我的使用结果:

其中 startTime 在午夜之后,endTime 在同一天午夜之前。

示例结果:

Pkg:com.android.chrome ForegroundTime:6412 秒上次使用时间:2018 年 4 月 19 日星期四 22:31:17 PDT


Pkg:com.instagram.android ForegroundTime:5415 秒上次使用时间:2018 年 4 月 19 日星期四 23:11:22 PDT


Pkg:com.android.chrome ForegroundTime:5304 秒上次使用时间:2018 年 4 月 19 日星期四 03:00:49 PDT


Pkg:com.instagram.android ForegroundTime:5202 秒上次使用时间:2018 年 4 月 19 日星期四 03:00:45 PDT

如您所见,对于某些事情,它会两次返回相同的包,最后一次使用的时间不同,即使最后一次使用的时间都是在我指定的 24 小时间隔内。

我在这里查看了一堆其他结果: Android UsageStatsManager 产生错误的输出?

如何使用 UsageStatsManager?

但似乎无法解决我的问题。

有谁知道它为什么会这样?好像和时间​​有关?尽管我当时正在熟睡,但对于某些包裹,最后使用的时间总是凌晨 3 点?

0 投票
2 回答
1408 浏览

android - 如何在android(kotlin)中使用usageStatsManager获取“当天”的使用统计信息

目标:
需要获取今天的使用统计信息(今天使用设备的总时间),即。上午 12 点至当前时间。

问题: 1.
我得到今天的时间 + 一些其他不可解释的时间2.不可解释
的时间戳(由 getTimestamp 方法检索的使用统计的开始和结束)
时间段不相关。我将开始时间定为上午 12 点,将结束时间定为当前时间,但是对于使用统计,我得到完全不相关的“.firstTimeStamp”和“.lastTimeStamp”(据说返回使用统计数据的开始和结束)。

*已经完成了权限授予部分,这是我用来获取总时间(以分钟为单位)的功能。

例如,当上述代码在 12 月 12 日星期三上午 12 点 40 分运行时,结果是:(
在 textView 中):
您花了 90 分钟
(在 textView2 中):
Tue 11 Dec 16:23:19 GMT +05:30 2018 to
Tue 12 月 11 日 19:38:45 GMT +05:30 2018

如何在短短 40 分钟内使用手机 90 分钟?
那些明显不相关的时间戳是什么意思?
我做错了什么来实现我的目标吗?