Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the currently running applications programmatically in Android?

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?

like image 918
pushpa Avatar asked Nov 11 '11 08:11

pushpa


1 Answers

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

like image 77
drooooooid Avatar answered Sep 22 '22 08:09

drooooooid