如何编程地查找Android的最后关闭日期?

发布于 2025-01-20 04:12:23 字数 649 浏览 4 评论 0原文

Android是否提供了一种简单的方法来在我的Java应用程序中以编程方式查找系统,当时系统关闭系统时是吗?我不是在寻找上次打开的时候,但上次关闭。

我找到了很多有关上次打开的信息。但是对我上次关闭时对我来说没什么用。

注意:为系统关闭设置广播听众无法适用于我的特定用例。这是因为当我的应用程序启动时,我需要知道何时最后关闭设备,即使我的应用程序(当时)被用户强迫。如果已被迫关闭,它将不会收到广播。


编辑:我尝试获取logcat记录,因为另一个线程中的评论表明,即使没有扎根设备或运行系统应用程序,除应用程序日志外,还可以使用一些(不多)的系统日志。但是,我能够根据 this Code 开始时,我能够根据

Does Android provide a simple way to find out programmatically in my Java app when the last datetime the system was turned off was? I'm not looking for when it was last turned on, but last turned off.

I've found lots of information for when it was last turned on. But nothing useful to me for when it was last turned off.

NOTE: Setting up a broadcast listener for system shutdowns is not going to work for my particular use-case. This is because when my app starts up I need to know when the device was last shut down, even if my app (at the time) had been forced-off by the user. It won't receive broadcasts if it has been forced off.


EDIT: I tried getting logcat records, since a comment in another thread indicated that even without rooting the device or running a system app, some (not many) system logs would be available in addition to app logs. However, the logs that I was able to see based on this code only start when the device itself starts. So that was no help.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文