简体   繁体   English

Android 查看应用程序是否已启动/在前台获取应用程序

[英]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.

相关问题 检测哪个应用已在Android中启动 - Detect which app has been launched in android 如何在应用程序启动时调用方法? 请看细节 - How to call a method only when the app has been launched? Please see details Android,如何在前台获取应用程序 - Android, how to get app on foreground 即使应用程序尚未启动,Android 中 WorkManager 的工作人员是否开始运行? - Does a worker from WorkManager in Android start to run even if the app has not been launched? 当 React Native Android 应用程序在后台或已被杀死时,如何将其带到前台? - How to bring a React Native Android app to the foreground when it is in the background or has been killed? Android:如何让应用程序记住是否已按下静音按钮 - Android: How to get app to remember if mute button has been pressed or not Android:如何获取前台应用的进程ID - Android: How to get the process id of the foreground app 如何通过BroadcastReceiver在Android中获取前台运行的应用程序 - How to get foreground running app in Android by BroadcastReceiver Android应用程序的前景用法 - Foreground usage for an Android app 在 android 8 上,当应用程序在前台有服务和通知时,后台子进程会被暂停吗? - on android 8, will the background child process get suspended when app has a service and a notification in the foreground?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM