I am very new to Android. I am working on application that must get the information about the applications currently running on foreground.
It means if user launches any applications, my application should capture the launched application information, by the time my application shouldn't interrupt launched application.
Example: If user launches browser application my application should print browser application information on log.
How can I do this?
ActivityManager activity_manager = (ActivityManager) context
.getSystemService(Activity.ACTIVITY_SERVICE);
ActivityManager
has method getRunningTasks(int)
. ActivityManager
seems to be the solution you are searching for.
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < recentTasks.size(); i++)
{
Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");
}
Also, have a look at following thread: See Android recent task executed by the user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With