Monday, November 8, 2010

List of Running ApplciationS

From the below snippet we can check the list of running applications and check whether your application is in foreground or not.

ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List procInfos = actvityManager.getRunningAppProcesses();

boolean appFound = false;

for(int i = 0; i < procInfos.size(); i++)
{
if(procInfos.get(i).processName == "com.android.camera")
appFound = true;
}

if (appFound)
Toast.makeText(getApplicationContext(), "Camera App is running!!!!", Toast.LENGTH_LONG).show();
else
Toast.makeText(getApplicationContext(), "Camera App is not running!!!!", Toast.LENGTH_LONG).show();

the above snippet shows your camera application is running or not.

2 comments:

  1. replace this line List procInfos = actvityManager.getRunningAppProcesses(); with below line for removing processNamne error in eclipse

    List procInfos = actvityManager.getRunningAppProcesses();

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete