简体   繁体   中英

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. 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. The newest solution that I could find is here: 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.

The proper way is to use UsageStatsManager for android 5+.
Here is a sample usage:
https://github.com/googlesamples/android-AppUsageStatistics

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM