[英]Android see if app has been launched / get the app in foreground
So I want to create a Service that can detect if another App has been launched.所以我想创建一个服务来检测是否已经启动了另一个应用程序。 But because there is not Event for detecting app launches, the plan is to check the app in the foreground every 10 seconds with AlarmManager or so and check if that app matches the app that im looking for.但是因为没有用于检测应用程序启动的事件,所以计划是每隔 10 秒使用 AlarmManager 左右检查前台中的应用程序,并检查该应用程序是否与我正在寻找的应用程序匹配。 The problem is that all the questions regarding this exact same problem are really really old.问题是关于这个完全相同的问题的所有问题都非常古老。 activityManager.getRunningTasks()
now only returns the own app and its tasks. activityManager.getRunningTasks()
现在只返回自己的应用程序及其任务。 The newest solution that I could find is here: How to get recent tasks on Android "L"?我能找到的最新解决方案在这里: How to get recent tasks on Android "L"? .But because this is also from 6 years ago, I was wondering if there are new ways or methods or if everything is still the same. .但是因为这也是6年前的事情,我想知道是否有新的方法或方法,或者一切都还是一样。
The proper way is to use UsageStatsManager for android 5+.正确的方法是对 android 5+ 使用UsageStatsManager 。
Here is a sample usage:这是一个示例用法:
https://github.com/googlesamples/android-AppUsageStatistics https://github.com/googlesamples/android-AppUsageStatistics
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.