Reputation: 31
I need some code to get an object or an arraylist that contains all the names of those applications that currently are in the recents stack of android. Maybe android doesn't permit to do that (for security reasons) so even code which needs root permissions is ok for me.
Upvotes: 3
Views: 2478
Reputation: 1419
Solution 1:
Use getRunningAppProcesses
, which will return a list of RunningAppProcessInfo
objects that will give you some data about each running app. One of the pieces of information you can retrieve about the app is its importance
, which can have a value IMPORTANCE_FOREGROUND
which indicates that the process is the currently active.
Some guide For you as well.
Solution 2: I was also developing an application for locking the apps. It seems you need to ask user to provide this setting. I used this activity to check which app is in foreground but I Guess it can work according to you also.
Settings.ACTION_USAGE_ACCESS_SETTINGS
On my mobile It's written
Allow apps to monitor which other apps you use and how often,and identify your service provider, language and other usage data.
UsageStatsManager
has some useful methods that can satisfy your need.
i think you need to ask this from your user and if the user agrees. you can use gain access to the recent Apps.
Upvotes: 1