当前位置:网站首页>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
边栏推荐
- Stm32mp157 wm8960 audio driver debugging notes
- Daily network security certification test questions (April 18, 2022)
- ESP32 LVGL8. 1 - img picture (IMG 20)
- 关于unity文件读取的操作(一)
- listener.log
- QT add external font ttf
- Daily CISSP certification common mistakes (April 15, 2022)
- Use of regular expressions in QT
- QT notes on qmap container freeing memory
- ESP32 LVGL8. 1 - slider slider (slider 22)
猜你喜欢

Druid SQL和Security在美团点评的实践

Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time

机器学习理论之(8):模型集成 Ensemble Learning

Machine learning theory (8): model integration ensemble learning

ctfshow-web362(SSTI)

Setting up keil environment of GD single chip microcomputer

实战业务优化方案总结---主目录---持续更新

【数学建模】—— 层次分析法(AHP)

ESP32 LVGL8. 1 - bar progress bar (bar 21)

【科普】CRC校验(一)什么是CRC校验?
随机推荐
Notepad + + replaces tabs with spaces
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Jeecg boot microservice architecture
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
CISSP certified daily knowledge points (April 15, 2022)
ESP32 LVGL8. 1 - checkbox (checkbox 23)
QT error: no matching member function for call to ‘connect‘
Loop path
Ionic 从创建到打包指令集顺序
Introduction to quantexa CDI syneo platform
ESP32 LVGL8. 1 - label (style 14)
MVVM模型
os_ authent_ Prefix
Practice of Druid SQL and security in meituan review
Interpretation and compilation of JVM
How to virtualize the video frame and background is realized in a few simple steps
机器学习实战 -朴素贝叶斯
【科普】CRC校验(一)什么是CRC校验?
Nacos集群搭建和mysql持久化配置
使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA