如何知道该应用已在 Android Q 中暂停?

How to know that app has been paused in Android Q?

有没有回调Android问应用暂停了? 在这种情况下,我想用应用程序做一些操作,但我找不到任何描述。

"Pause app" 是 Android 的新功能 问: https://9to5google.com/2019/05/21/digital-wellbeing-pixel-launch-pause-app/

不是 onPause() 生命周期方法。

对于其他对他的问题投反对票的用户 - 这是关于 Google 的 Digital Wellbeing 程序中的一项功能,该程序已推送到 Pixel 手机 - 而不是关于 activity 生命周期

对于 OP - 我不认为你会得到一个满意的答案。我查看了 Android Q Beta documentation,他们没有提供指向任何特定内容的链接。然而对于未来的开发者来说,我认为搜索的术语是"distraction state",正如他们的文档中提到的那样:

Per-app distraction state -- Android Q can now selectively set apps to a "distraction state" where their notifications are suppressed and they will not appear as suggested apps.

目前我唯一可以建议的是不要在 gradle 中瞄准 android Q。所以今天的正确答案是这个信息/api还没有public

由于目前没有关于此问题的官方文档,我将此作为答案发布,希望会有官方解决方案。

您可以使用 Intent 过滤器注册 BroadcastReceiver Intent.ACTION_PACKAGES_SUSPENDED。一旦您将应用程序置于此模式,它将被触发。

但我不确定它不会有副作用或在所有设备上都能稳定运行。我在 Pixel 2 上试过了。

当前 post。没有关于 Android Q Pause App featureAndroid Activity Lifecycle and how to apps can track this action. But based on my understanding of how Pause App feature works from the post i read here 相关的文档是,来自该应用程序的所有通知都被禁用,并且从启动器中选择该应用程序也被禁用。

App paused using Pause App feature can still be running but can neither be resumed/launched nor send new notifications.

这是我认为 paused app 可以做的事情来验证它在定位时是否暂停 android 问。虽然不够有效。

  • 应用程序在启动期间使用 startForeground 启动通知,因此它不会被用户关闭。显示类似 MyApp is running.
  • 的内容
  • 应用程序使用 运行 foreground service 定期检查通知状态 every nth minutes
  • 如果服务是 still running and the foreground notification is closed or cannot be found 的服务,那么逻辑上我们可以说应用程序在 paused state.