How to get recent used applications pragmatically?

45 Views Asked by At

I am trying to implement the add recently opened application in my application. I am trying to do with the getRunningAppProcess() but it gives me only my application details. Also, tried with the getSystemService(), but didn't get any lead. Found the upvote solution of UsageStats, it also gives only my application details.

 Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, -5);

        final List<UsageStats> stats =
                mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST,
                        cal.getTimeInMillis(), System.currentTimeMillis());
        if (stats == null) {
            return;
        }

 <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
    tools:ignore="ProtectedPermissions" />
1

There are 1 best solutions below

0
ismail alaoui On

i advice you to check App usage statistics API on github , it will allow you to collect statistics related to usage of the applications. it provides more detailed usage information than the deprecated getRecentTasks() method.