查明设备是否在没有 BOOT_COMPLETED 的情况下重新启动/崩溃
我需要知道设备是否已崩溃或重新启动,并且希望避免使用 BOOT_COMPLETED
权限。
这可能吗?我正在考虑读出正常运行时间并进行比较(我如何读出它?)或者有更好的方法吗?
I need to know if the device has crashed or rebooted and would like to avoid using a BOOT_COMPLETED
permission.
Is that possible? I was thinking of reading out the uptime and compare it (how do I read it out?) Or is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当他们比上次“更早”启动应用程序时(正如您所知),读取正常运行时间才会对您有所帮助。您可以使用 SystemClock.elapsedRealtime() 如果你无论如何都想走这条路。
另一种解决方案(尽管未经测试)是:
此文件将包含一个每次重新启动时都会不同的 uuid。
Reading the uptime will only help you when they have started the app "earlier" than last time (as you already know). You can read the uptime using SystemClock.elapsedRealtime() if you want to go down that path anyway.
An alternative solution, although untested, is to read:
This file will contain a uuid that will be different on every restart.