使用服务来监视其他活动/应用程序何时启动或结束

发布于 2024-08-24 20:06:00 字数 75 浏览 2 评论 0原文

是否可以使在后台运行的服务在用户启动和结束任意活动/应用程序时收到通知?我想用它来记录 Android 中不同应用程序的使用频率和时长。

Is it possible to make a service running in backgroud to be notified when an arbritary activity/application is started and ended by a user? I want to use it to log how often and for how long different applications are used in Android.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就像说晚安 2024-08-31 20:06:00

看看ActivityManager.getRunningTasks()。不幸的是,您需要连续运行才能看到任务的启动和停止。我不知道您可以收听任何事件。

Have a look at ActivityManager.getRunningTasks(). Unfortunately you would need to be running continuously to see tasks starting and stopping. I'm not aware of any event you can listen for.

云巢 2024-08-31 20:06:00

正如问题中所述答案发布如下:

除了定期读取进程列表并检测前台进程之外,没有其他解决方案。您需要为此提供服务。遗憾的是,Android并没有提供前台进程变化的广播事件等手段。

用于监控 Android 上其他应用的应用回复其中包含有趣且有用的建议和一些示例代码。

As stated in question & answer posted bellow:

There is no solution other than periodically read a list of processes and detecting foreground process. You need a service for this. Unfortunately, Android does not provide means such as broadcast events for foreground process change.

App to monitor other apps on android and the reply which contains interesting and usefull suggestion and some sample code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文