当前位置:网站首页>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
边栏推荐
- Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
- Daily CISSP certification common mistakes (April 12, 2022)
- 特征选择feature_selection--SelectKBest
- Daily network security certification test questions (April 12, 2022)
- Halo open source project learning (VII): caching mechanism
- ESP32 LVGL8. 1 - BTN button (BTN 15)
- The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
- CISSP certified daily knowledge points (April 14, 2022)
- Daily network security certification test questions (April 13, 2022)
- Nacos作为服务配置中心实战
猜你喜欢
iptables -L执行缓慢
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
纠结
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
ctfshow-web362(SSTI)
Imx6 debugging LVDS screen technical notes
Summary of actual business optimization scheme - main directory - continuous update
七、DOM(下) - 章节课后练习题及答案
Machine learning theory (8): model integration ensemble learning
How to virtualize the video frame and background is realized in a few simple steps
随机推荐
Summary of actual business optimization scheme - main directory - continuous update
数据库上机实验四(数据完整性与存储过程)
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
How can programmers quickly develop high-quality code?
Deeply understand what new and make in golang are and what are the differences?
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
Custom prompt box MessageBox in QT
QT error: no matching member function for call to ‘connect‘
Promote QT default control to custom control
Setting up keil environment of GD single chip microcomputer
纠结
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
Mysql database backup command -- mysqldump
ESP32 LVGL8. 1 - roller rolling (roller 24)
ESP32 LVGL8. 1 - slider slider (slider 22)
ctfshow-web362(SSTI)
Cutting permission of logrotate file
Daily network security certification test questions (April 15, 2022)
Daily network security certification test questions (April 13, 2022)
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)