UsageStatsManager 未在 android 11 中使用 PACKAGE_USAGE_STATS 的权限

UsageStatsManager is not working in android 11 with permission of PACKAGE_USAGE_STATS

我的应用程序在 android 的 10 及更低版本中运行良好。我查看了文档,他们说使用统计功能有所改变(即 https://developer.android.com/about/versions/11/behavior-changes-all#app-usage-stats)有什么帮助吗?

经过两天的努力,我找到了解决问题的办法。实际上 context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA); 应该 return 所有已安装应用程序的列表,但在 android 11 中它只会 return 系统应用程序列表。要获取所有应用程序(系统+用户)的列表,我们需要为应用程序提供额外的权限,即