String topActivity = "";
UsageStatsManager m = (UsageStatsManager) mContext.getSystemService(Context.USAGE_STATS_SERVICE);
if (m != null) {
long now = System.currentTimeMillis();
List<UsageStats> stats = m.queryUsageStats(UsageStatsManager.INTERVAL_BEST, now - 60 * 1000, now);
if ((stats != null) && (!stats.isEmpty())) {
int j = 0;
for (int i = 0; i < stats.size(); i++) {
if (stats.get(i).getLastTimeUsed() > stats.get(j).getLastTimeUsed()) {
j = i;
}
}
topActivity = stats.get(j).getPackageName();
}
}
获取正在运行的apk activity
最新推荐文章于 2022-09-20 15:19:10 发布