当前位置:网站首页>Get a list of recent apps
Get a list of recent apps
2022-04-23 18:41:00 【tanleicsdn】
To get the list of recently used apps UsageStatsManager class , You also need to apply for permission to allow the use of defense applications .
private void getPackagesInfo() {
UsageStatsManager manager = (UsageStatsManager) getApplicationContext().getSystemService(USAGE_STATS_SERVICE);
List<UsageStats> stats = manager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, PhoneUtils.getTimesMorning().getTime(), PhoneUtils.getTimesNight().getTime());
PackageManager pm = getPackageManager();
for (UsageStats us : stats) {
ApplicationInfo applicationInfo = null;
try {
applicationInfo = pm.getApplicationInfo(us.getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (applicationInfo != null) {
if ((applicationInfo.flags & applicationInfo.FLAG_SYSTEM) <= 0) {
" Application duration " = (int) (us.getTotalTimeInForeground() / 1000);
" apply name " = applicationInfo.loadLabel(getPackageManager()).toString();
}
}
}
}
public class PhoneUtils {
// Get the day 0 Point time
public static Date getTimesMorning() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return (cal.getTime());
}
// Get the day 24 Point time
public static Date getTimesNight() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 24);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
// Get the day 24 Time stamp
public static long getTimesNow() {
return System.currentTimeMillis();
}
}
The above completes the function of obtaining the duration of recently used applications .
版权声明
本文为[tanleicsdn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210604297388.html
边栏推荐
- Machine learning theory (7): kernel function kernels -- a way to help SVM realize nonlinear decision boundary
- 玻璃体中的硫酸软骨素
- 22年字节跳动飞书人力套件三面面经
- Notepad + + replaces tabs with spaces
- 教你用简单几个步骤快速重命名文件夹名
- Halo 开源项目学习(七):缓存机制
- Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
- Fundamentals of machine learning theory -- some terms about machine learning
- Mysql database backup command -- mysqldump
- Introduction to quantexa CDI syneo platform
猜你喜欢
Iptables - L executes slowly
机器学习实战 -朴素贝叶斯
ESP32 LVGL8. 1 - img picture (IMG 20)
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
listener. log
机器学习理论之(8):模型集成 Ensemble Learning
Esp32 (UART ecoh) - serial port echo worm learning (2)
随机推荐
Seata handles distributed transactions
Fundamentals of machine learning theory -- some terms about machine learning
回路-通路
QT excel operation summary
Daily CISSP certification common mistakes (April 13, 2022)
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
STM32: LCD显示
ESP32 LVGL8. 1 - arc (arc 19)
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
Esp32 (UART ecoh) - serial port echo worm learning (2)
Daily network security certification test questions (April 12, 2022)
Daily network security certification test questions (April 18, 2022)
Nacos集群搭建和mysql持久化配置
Practice of Druid SQL and security in meituan review
CISSP certified daily knowledge points (April 15, 2022)
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
Implementation of TCP UDP communication with golang language
14 py games source code share the second bullet