当前位置:网站首页>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
边栏推荐
- 【数学建模】—— 层次分析法(AHP)
- 特征选择feature_selection--SelectKBest
- ctfshow-web362(SSTI)
- Multifunctional toolbox wechat applet source code
- Machine learning practice - naive Bayes
- Daily CISSP certification common mistakes (April 14, 2022)
- Esp32 (UART ecoh) - serial port echo worm learning (2)
- Fundamentals of machine learning theory -- some terms about machine learning
- Serial port debugging tools cutecom and minicom
- QT notes on qmap container freeing memory
猜你喜欢

七、DOM(下) - 章节课后练习题及答案

使用晨曦记账本,分析某个时间段每个账户收支结余

解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本

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

ESP32 LVGL8. 1 - label (style 14)

In win10 system, all programs run as administrator by default

Teach you to quickly rename folder names in a few simple steps

How to restore MySQL database after win10 system is reinstalled (mysql-8.0.26-winx64. Zip)

The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an

kettle庖丁解牛第17篇之文本文件输出
随机推荐
STM32: LCD显示
About the operation of unit file reading (I)
CISSP certified daily knowledge points (April 18, 2022)
ctfshow-web361(SSTI)
根据快递单号查询物流查询更新量
logstash 7. There is a time problem in X. the difference between @ timestamp and local time is 8 hours
ESP32 LVGL8. 1 - label (style 14)
Druid SQL和Security在美团点评的实践
STM32: LCD display
CISSP certified daily knowledge points (April 13, 2022)
C language simulates entering and leaving the stack, first in first out, first in first out, shared memory
ctfshow-web362(SSTI)
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
Feature selection feature_ selection--SelectKBest
特征选择feature_selection--SelectKBest
Introduction to QT programming
Mysql database backup command -- mysqldump
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
Const keyword, variable and function are decorated with const
QT tablewidget insert qcombobox drop-down box